Java Code Examples for javax.faces.application.FacesMessage#SEVERITY_ERROR

The following examples show how to use javax.faces.application.FacesMessage#SEVERITY_ERROR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CaptchaValidator.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * 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));
    }
}
 
Example 2
Source File: AbsOrRelUrlValidator.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * 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));
}
 
Example 3
Source File: SimulatorInstController.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
public String edit(SimulatorInst simulatorInstToEdit) {
    log.log(Level.INFO, " edit enter:: [" + simulatorInstToEdit.toString() + "]");
    FacesContext context = FacesContext.getCurrentInstance();
    ResourceBundle bundle = context.getApplication().getResourceBundle(context, "msg");

    this.simulatorInst = pmanager.findSimulator(simulatorInstToEdit.getSimulator(), simulatorInstToEdit.getVersion());
    try {
        if (simulatorInst != null) {
            log.log(Level.INFO, "Edit SimulatorInst : [" + simulatorInst.getId() + " " + simulatorInst.getSimulator().name() + " " + simulatorInst.getVersion() + "]");
            return "edit";
        } else {
            throw new Exception("Edit: SimulatorInst not found!");
        }
    } catch (Exception e) {
        log.log(Level.WARNING, "edit simulator:: catch an Exception" + e.getMessage());
        String errorMessage = getRootErrorMessage(e);
        FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, bundle.getString("edit.failure.msg"));
        facesContext.addMessage(null, m);
        return "edit";
    }
}
 
Example 4
Source File: EmailValidator.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Validates that the given value contains an email address.
 * 
 * @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 email = value.toString();
    if (email.length() == 0) {
        return;
    }
    if (!ADMValidator.isEmail(email)) {
        Object[] args = null;
        String label = JSFUtils.getLabel(component);
        if (label != null) {
            args = new Object[] { label };
        }
        ValidationException e = new ValidationException(
                ValidationException.ReasonEnum.EMAIL, label, null);
        String text = JSFUtils.getText(e.getMessageKey(), args,
                facesContext);
        throw new ValidatorException(new FacesMessage(
                FacesMessage.SEVERITY_ERROR, text, null));
    }
}
 
Example 5
Source File: ModelTemplateContainerController.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
public String edit(String ddbId) {
    log.info(" edit enter:: parameter ddbId: " + ddbId);
    FacesContext context = FacesContext.getCurrentInstance();
    ResourceBundle bundle = context.getApplication().getResourceBundle(context, "msg");
    this.modelTemplateContainer = pmanager.findModelTemplateContainer(ddbId);
    this.currentddbid = ddbId;
    this.ddbId = ddbId;
    try {
        if (modelTemplateContainer != null) {
            buildDefParamTable();
            return "/modelTemplateContainer/edit?faces-redirect=true&includeViewParams=true";
        } else {
            throw new Exception("Edit:modelTemplateContainer IS NULL");
        }
    } catch (Exception e) {
        log.log(Level.WARNING, "Edit: Edit: modelTemplateContainer IS NULL");
        String errorMessage = getRootErrorMessage(e);
        FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_ERROR,    errorMessage, bundle.getString("edit.failure.msg"));
        facesContext.addMessage(null, m);
        return "list?faces-redirect=true";
    }
}
 
Example 6
Source File: InternalController.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
public String edit(Internal internal) {
    log.log(Level.INFO, " edit enter:: [" + internal.getNativeId() + "]");
    this.nativeId = internal.getNativeId();
    FacesContext context = FacesContext.getCurrentInstance();
    ResourceBundle bundle = context.getApplication().getResourceBundle(context, "msg");
    try {
        this.newInternal = pmanager.findInternal(internal.getNativeId());
        if (internal != null) {
            log.log(Level.INFO, "Edit Internal : [" + internal.getNativeId() + "]");
            return "edit?faces-redirect=true&includeViewParams=true";
        } else {
            throw new Exception("Edit: Internal not found!");
        }

    } catch (Exception e) {
        log.log(Level.WARNING, "edit Internal:: catch an Exception" + e.getMessage());
        String errorMessage = getRootErrorMessage(e);
        FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, bundle.getString("edit.failure.msg"));
        facesContext.addMessage(null, m);
        return "edit";
    }
}
 
Example 7
Source File: ParametersContainerController.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
public String edit(String ddbId) {
    log.log(Level.INFO, " edit enter:: parameter ddbId: " + ddbId);
    log.log(Level.INFO, " Create add ParametersContainer: [ddbId:" + parametersContainer.getDdbId() + "] " +
            "                        - [Parameters [defParamSetNum " + newParameters.getDefParamSetNum() + " simulator " + newParameters.getSimulator() + "]");
    FacesContext context = FacesContext.getCurrentInstance();
    ResourceBundle bundle = context.getApplication().getResourceBundle(context, "msg");
    this.ddbId = ddbId;
    this.parametersContainer = pmanager.findParametersContainer(ddbId);
    try {
        if (parametersContainer != null) {
            this.sortParameters();
            return "edit?faces-redirect=true&includeViewParams=true";
        } else {
            throw new Exception("Edit:parametersContainer not found!");
        }

    } catch (Exception e) {
        log.log(Level.WARNING, "Edit: Edit: parametersContainer not found");
        String errorMessage = getRootErrorMessage(e);
        FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, bundle.getString("edit.failure.msg"));
        facesContext.addMessage(null, m);
        return "edit";
    }
}
 
Example 8
Source File: FloatValidator.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void validate(FacesContext context, UIComponent component, Object objValue) throws ValidatorException {
    String objString = objValue.toString();
    ResourceBundle bundle = context.getApplication().getResourceBundle(context, "msg");
    boolean valid = true;
    try {
        Float valueFloat = Float.valueOf(objString);
    } catch (NumberFormatException nEx) {
        valid = false;

    }
    if (!valid) {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, bundle.getString("invalid.float.summary.msg"),
                bundle.getString("invalid.float.detail.msg"));

        throw new ValidatorException(message);
    }
}
 
Example 9
Source File: ParameterValueValidator.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Validate integer value.
 * 
 * @param context
 *            JSF context.
 * @param uiComponent
 *            UI component.
 * @param value
 *            Value for validation.
 */
private void validateInteger(FacesContext context, UIComponent uiComponent,
        String value) {
    if (!GenericValidator.isInt(value.toString())) {
        Object[] args = null;
        String label = JSFUtils.getLabel(uiComponent);
        if (label != null) {
            args = new Object[] { label };
        }
        ValidationException e = new ValidationException(
                ValidationException.ReasonEnum.INTEGER, label, null);
        String text = JSFUtils.getText(e.getMessageKey(), args, context);
        throw new ValidatorException(new FacesMessage(
                FacesMessage.SEVERITY_ERROR, text, null));
    }
}
 
Example 10
Source File: GeneralBean.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
public void showGrowlMessage() {
	String severityRaw = BeanUtil.getRequestParam("Severity");
	String summary = BeanUtil.getRequestParam("Summary");
	String detail = BeanUtil.getRequestParam("Detail");

       Severity severity;

       if("WARN".equals(severityRaw)) {
		severity = FacesMessage.SEVERITY_WARN;
       } else if("ERROR".equals(severityRaw)) {
		severity = FacesMessage.SEVERITY_ERROR;
	} else {
		severity = FacesMessage.SEVERITY_INFO;
	}

	BeanUtil.showMessage(severity, summary, detail);
}
 
Example 11
Source File: ParameterValueValidator.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a default faces message.
 * 
 * @param component
 *            The current component.
 * @return The faces message.
 */
public static FacesMessage getFacesMessage(UIComponent component,
        FacesContext context) {
    String label = JSFUtils.getLabel(component);
    Long maxVal = LongValidator.getMaxValue(component);
    if (maxVal == null) {
        maxVal = DurationValidation.getDurationMaxDaysValue();
    }
    Object[] args = new Object[] { maxVal.toString() };

    ValidationException e = new ValidationException(
            ValidationException.ReasonEnum.DURATION, label, null);
    String text = JSFUtils.getText(e.getMessageKey(), args, context);
    return new FacesMessage(FacesMessage.SEVERITY_ERROR, text, null);
}
 
Example 12
Source File: UserConverter.java    From aws-photosharing-example with Apache License 2.0 5 votes vote down vote up
public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
    if(value != null && value.trim().length() > 0) {
        try {
        	return getFacade().findUser(Long.parseLong(value));                
        } catch(NumberFormatException e) {
            throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid user id."));
        }
    }
    else {
        return null;
    }
}
 
Example 13
Source File: PaddingConverter.p.vm.java    From javaee-lab with Apache License 2.0 5 votes vote down vote up
private int getPadding(FacesContext context, UIComponent component) {
    if (component.getAttributes() != null && component.getAttributes().containsKey(PADDING_PARAMETER)) {
        return Integer.valueOf((String) component.getAttributes().get(PADDING_PARAMETER));
    } else {
        String message = messageSource.getMessage(PADDING_ID, null, context.getViewRoot().getLocale());
        throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, message, null));
    }
}
 
Example 14
Source File: ModelTemplateController.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
public String deleteMT() {
    log.log(Level.INFO, "delete MT");
    FacesContext context = FacesContext.getCurrentInstance();
    ResourceBundle bundle = context.getApplication().getResourceBundle(context, "msg");

    try {
        ModelTemplateContainer modelTemplateContainer = pmanager.findModelTemplateContainer(this.currentddbid);
        List<ModelTemplate> modelTemplates = modelTemplateContainer.getModelTemplates();
        for (ModelTemplate mt : modelTemplates) {
            if (mt.getId().compareTo(currentId) == 0) {
                this.modelTemplate = mt;
            }
        }

        modelTemplates.remove(this.modelTemplate);
        log.log(Level.INFO, "deleteMT:  ModelTemplatesList  after remove  "    + modelTemplates.contains(this.modelTemplate));
        modelTemplateContainer.setModelTemplates(modelTemplates);
        modelTemplateContainer = pmanager.save(modelTemplateContainer);
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, this.modelTemplate.getComment() + " " + bundle.getString("delete.operation.msg"), bundle.getString("success.msg"));
        FacesContext.getCurrentInstance().addMessage(null, msg);
        return "../modelTemplateContainer/list.jsf";

    } catch (Exception ex) {
        String errorMessage = getRootErrorMessage(ex);
        log.log(Level.WARNING, "Error  " + errorMessage);
        FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_ERROR,    errorMessage, bundle.getString("delete.failure.msg"));
        facesContext.addMessage(null, m);
        return "edit";

    }
}
 
Example 15
Source File: DateFromToValidator.java    From development with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 16
Source File: LanguageISOCodeValidator.java    From development with Apache License 2.0 5 votes vote down vote up
private void addMessage(String languageISOCode, FacesContext facesContext,
        String key) {
    String text = JSFUtils.getText(key, new String[] { languageISOCode },
            facesContext);
    throw new ValidatorException(new FacesMessage(
            FacesMessage.SEVERITY_ERROR, text, null));
}
 
Example 17
Source File: EmailValidator.java    From Tutorials with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
	matcher = pattern.matcher(value.toString());
	if(!matcher.matches()){
		throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid e-mail address", null));
	}
}
 
Example 18
Source File: BusinessException.java    From admin-template with MIT License 4 votes vote down vote up
public FacesMessage.Severity getSeverity() {
    if(severity == null){
        severity = FacesMessage.SEVERITY_ERROR;
    }
    return severity;
}
 
Example 19
Source File: CssColorValidator.java    From development with Apache License 2.0 4 votes vote down vote up
/**
 * Validates that the given value contains a css color definition.
 * 
 * @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 color = value.toString();
    String orig_value = color;
    if (color.length() == 0) {
        return;
    }
    // remove all white spaces also inside the string
    color = color.replaceAll("\\s", "");

    // hex
    if (color.matches("#[a-fA-F0-9]*")
            && (color.length() == 4 || color.length() == 7)) {
        return;
    }

    // rgb
    if (color.matches("[rR][gG][bB]\\([\\d,%]*\\)")) {
        color = color.substring(4, color.length() - 1);
        String a[] = null;
        int max;
        if (color.indexOf("%") >= 0) {
            color = color.replaceAll("%", "");
            max = 100;
        } else {
            max = 255;
        }
        a = color.split(",");
        if (containsNumbersInRange(a, 10, 0, max)) {
            return;
        }
    }

    if (colorSet.contains(color.toLowerCase())) {
        return;
    }

    Object[] args = new Object[] { orig_value };
    // Object[] args = null;
    String label = JSFUtils.getLabel(component);
    // if (label != null) {
    // args = new Object[] { label, orig_value };
    // } else {
    // args = new Object[] { "", orig_value };
    // }
    ValidationException e = new ValidationException(
            ValidationException.ReasonEnum.CSS_COLOR, label, null);
    String text = JSFUtils.getText(e.getMessageKey(), args, facesContext);
    throw new ValidatorException(new FacesMessage(
            FacesMessage.SEVERITY_ERROR, text, null));
}
 
Example 20
Source File: FacesMessages.java    From BootsFaces-OSP with Apache License 2.0 4 votes vote down vote up
public static void error(String refItem, String summary, String detail) {
	FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, detail);
	reportMessage(refItem, facesMsg);
}