本文整理汇总了Java中javax.faces.application.FacesMessage.SEVERITY_ERROR属性的典型用法代码示例。如果您正苦于以下问题:Java FacesMessage.SEVERITY_ERROR属性的具体用法?Java FacesMessage.SEVERITY_ERROR怎么用?Java FacesMessage.SEVERITY_ERROR使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.faces.application.FacesMessage
的用法示例。
在下文中一共展示了FacesMessage.SEVERITY_ERROR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: show
public void show() {
FacesContext instance = FacesContext.getCurrentInstance();
String msg;
if (StringUtils.isEmpty(template)) {
msg = text;
if (severity == null) { // If we are using text, and the developer didn't specify a severity => Assume ERROR.
severity = FacesMessage.SEVERITY_ERROR;
}
} else {
msg = messageContext.message().template(template).argument(arguments).toString();
if (severity == null) {
severity = determineSeverity(template);
}
}
instance.addMessage(clientId, new FacesMessage(severity, msg, msg));
if (clientId != null) {
UIComponent component = instance.getViewRoot().findComponent(clientId);
if (component instanceof UIInput && FacesMessage.SEVERITY_ERROR.equals(severity)) {
((UIInput) component).setValid(false);
}
}
resetData();
}
示例2: validate
/**
* Validates that the given value is a relative or absolute URL
*
* @param context
* FacesContext for the request we are processing
* @param component
* UIComponent we are checking for correctness
* @param value
* the value to validate
* @throws ValidatorException
* if validation fails
*/
public void validate(FacesContext facesContext, UIComponent component,
Object value) throws ValidatorException {
if (value == null) {
return;
}
String str = value.toString();
if (str.length() == 0) {
return;
}
if (ADMValidator.isAbsoluteOrRelativeUrl(str)) {
return;
}
Object[] args = null;
String label = JSFUtils.getLabel(component);
if (label != null) {
args = new Object[] { label };
}
ValidationException e = new ValidationException(
ValidationException.ReasonEnum.URL, label, null);
String text = JSFUtils.getText(e.getMessageKey(), args, facesContext);
throw new ValidatorException(new FacesMessage(
FacesMessage.SEVERITY_ERROR, text, null));
}
示例3: validate
/**
* Validates if the user input and captchaInputField contain the same value
*
* @param context
* FacesContext for the request we are processing
* @param component
* UIComponent we are checking for correctness
* @param value
* the value to validate
* @throws ValidatorException
* if validation fails
*/
@Override
public void validate(final FacesContext context,
final UIComponent captchaInputField, final Object value)
throws ValidatorException {
String userInput = (String) value;
String captchaKey = (String) JSFUtils
.getSessionAttribute(Constants.CAPTCHA_KEY);
if (userInput != null && userInput.equals(captchaKey)) {
JSFUtils.setSessionAttribute(Constants.CAPTCHA_INPUT_STATUS,
Boolean.TRUE);
} else {
HtmlInputText htmlInputText = (HtmlInputText) captchaInputField;
htmlInputText.setValid(false);
JSFUtils.setSessionAttribute(Constants.CAPTCHA_INPUT_STATUS,
Boolean.FALSE);
htmlInputText.setValue("");
String text = JSFUtils.getText(BaseBean.ERROR_CAPTCHA,
(Object[]) null);
throw new ValidatorException(new FacesMessage(
FacesMessage.SEVERITY_ERROR, text, null));
}
}
示例4: getMessage
/**
* Creates a FacesMessage for the given Throwable.
* The severity is {@link FacesMessage#SEVERITY_ERROR}
* @param error The root cause of this Exception will be used.
*/
public static FacesMessage getMessage(Throwable error)
{
_LOG.fine(error);
Throwable unwrap = ComponentUtils.unwrap(error);
String detail = unwrap.getLocalizedMessage();
if (detail == null)
{
// this is unusual. It is probably an unexpected RT error
// in the framework. log at warning level:
detail = unwrap.getClass().getName();
_LOG.warning(error);
}
// bug 4733165:
FacesMessage message =
new FacesMessage(FacesMessage.SEVERITY_ERROR, null, detail);
return message;
}
示例5: validate
@Override
public void validate(FacesContext context, UIComponent uiComponent,
Object input) throws ValidatorException {
TenantService tenantService = serviceLocator.findService(TenantService.class);
String tenantKey = input.toString();
if (StringUtils.isBlank(tenantKey) || "0".equals(tenantKey)) {
return;
}
try {
tenantService.getTenantByKey(Long.parseLong(tenantKey));
} catch (ObjectNotFoundException e) {
String msg = JSFUtils
.getText(BaseBean.ERROR_TENANT_NO_LONGER_EXISTS, null);
FacesMessage facesMessage = new FacesMessage(
FacesMessage.SEVERITY_ERROR, msg, null);
throw new ValidatorException(facesMessage);
}
}
示例6: constructValidatorException
private ValidatorException constructValidatorException(
final FacesContext context, final UIComponent component) {
// create ValidationException
String label = JSFUtils.getLabel(component);
ValidationException ex = new ValidationException(
ValidationException.ReasonEnum.URL, label, null);
// map to ValidatorException
Object[] args = null;
if (label != null) {
args = new Object[] { label };
}
String text = JSFUtils.getText(ex.getMessageKey(), args, context);
return new ValidatorException(new FacesMessage(
FacesMessage.SEVERITY_ERROR, text, null));
}
示例7: validate
/**
* Validates that the given value contains an currency ISO code.
*
* @param context
* FacesContext for the request we are processing
* @param component
* UIComponent we are checking for correctness
* @param value
* the value to validate
* @throws ValidatorException
* if validation fails
*/
public void validate(FacesContext facesContext, UIComponent component,
Object value) throws ValidatorException {
if (value == null) {
return;
}
String currencyCode = value.toString();
if (currencyCode.length() == 0) {
return;
}
try {
Currency.getInstance(currencyCode);
} catch (IllegalArgumentException e) {
String label = JSFUtils.getLabel(component);
ValidationException ve = new ValidationException(
ReasonEnum.INVALID_CURRENCY, label,
new Object[] { currencyCode });
String text = JSFUtils.getText(ve.getMessageKey(),
new Object[] { currencyCode }, facesContext);
throw new ValidatorException(new FacesMessage(
FacesMessage.SEVERITY_ERROR, text, null));
}
}
示例8: validate
/**
* Validates that the given value doesn't contain a '{', '}' or "/*".
*
* @param context
* FacesContext for the request we are processing
* @param component
* UIComponent we are checking for correctness
* @param value
* the value to validate
* @throws ValidatorException
* if validation fails
*/
public void validate(FacesContext facesContext, UIComponent component,
Object value) throws ValidatorException {
if (value == null) {
return;
}
String str = value.toString();
if (str.indexOf('{') < 0 && str.indexOf('}') < 0
&& str.indexOf("/*") < 0) {
return;
}
Object[] args = null;
String label = JSFUtils.getLabel(component);
// if (label != null) {
// args = new Object[] { label, str };
// } else {
// args = new Object[] { "", str };
// }
ValidationException e = new ValidationException(
ValidationException.ReasonEnum.CSS_VALUE, label, null);
String text = JSFUtils.getText(e.getMessageKey(), args, facesContext);
throw new ValidatorException(new FacesMessage(
FacesMessage.SEVERITY_ERROR, text, null));
}
示例9: handleException
public static String handleException(Exception e) {
String genericNavState = ERROR;
String msg = e.toString();
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
getCurrentInstance().addMessage(ERROR, message);
return genericNavState;
}
示例10: handleError
protected void handleError(final FacesContext facesContext,
@SuppressWarnings("unused") final String clientid,
final String msgKey) throws ValidatorException {
String text = JSFUtils.getText(msgKey, null, facesContext);
throw new ValidatorException(new FacesMessage(
FacesMessage.SEVERITY_ERROR, text, null));
}
示例11: hasErrors
public static boolean hasErrors(FacesContext fc) {
for (Iterator<FacesMessage> i = fc.getMessages(); i.hasNext();) {
FacesMessage m = i.next();
if (FacesMessage.SEVERITY_ERROR == m.getSeverity()) {
return true;
}
}
return false;
}
示例12: addErrorMsg
public static void addErrorMsg(String mensagem)
{
FacesContext facesContext = FacesContext.getCurrentInstance();
FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR, mensagem, mensagem);
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, fm);
}
示例13: validate
@Override
public void validate(FacesContext context, UIComponent component,
Object valueToValidate) throws ValidatorException {
if (valueToValidate == null) {
return;
}
UserManagementService service = srvLocator
.findService(UserManagementService.class);
String organizationId;
try {
organizationId = retrieveOrganizationId(valueToValidate);
if (service.isOrganizationLDAPManaged(organizationId)) {
ValidationException e = new ValidationException(
ValidationException.ReasonEnum.LDAP_USER_ID, null, null);
String text = JSFUtils
.getText(e.getMessageKey(), null, context);
throw new ValidatorException(new FacesMessage(
FacesMessage.SEVERITY_ERROR, text, null));
}
} catch (ObjectNotFoundException | OperationNotPermittedException
| OrganizationRemovedException e1) {
return;
}
}
示例14: login
/**
* Process login. Connect to server and move to folder display page.
*/
public String login()
{
try
{
// login to the IMAP server
Properties props = new Properties();
Session session = Session.getInstance(props, null);
Store store = session.getStore("imap");
store.connect(_server, _username, _password);
setStore(store);
setRootFolders(FolderData.toFolderData(this, store.getDefaultFolder().list()));
// TODO: Add logged in indicator to restrict access
_gotoFolder(null);
// Set up the user's preferences; in a real app, these would
// be persisted somewhere.
PreferencesData preferences = new PreferencesData();
setPreferences(preferences);
}
// catch all exceptions and report them as errors
catch (Exception e)
{
FacesMessage errorMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR,
e.getMessage(), null);
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, errorMessage);
return null;
}
return "success";
}
示例15: setErrorMessage
public static void setErrorMessage(String id, String msg) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
getCurrentInstance().addMessage(id, message);
}