Search in sources :

Example 1 with StringLengthConstraint

use of org.alfresco.repo.dictionary.constraint.StringLengthConstraint in project acs-community-packaging by Alfresco.

the class BaseComponentGenerator method setupStringLengthConstraint.

/**
 * Sets up a default validation rule for the string length constraint
 *
 * @param context FacesContext
 * @param propertySheet The property sheet to add the validation rule to
 * @param property The property being generated
 * @param component The component representing the property
 * @param constraint The constraint to setup
 * @param realTimeChecking true to make the client validate as the user types
 */
protected void setupStringLengthConstraint(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem property, UIComponent component, StringLengthConstraint constraint, boolean realTimeChecking) {
    int min = constraint.getMinLength();
    int max = constraint.getMaxLength();
    List<String> params = new ArrayList<String>(3);
    // add the value parameter
    String value = "document.getElementById('" + component.getClientId(context) + "')";
    params.add(value);
    // add the min parameter
    params.add(Integer.toString(min));
    // add the max parameter
    params.add(Integer.toString(max));
    // add the validation failed message to show
    String msg = Application.getMessage(context, "validation_string_length");
    addStringConstraintParam(params, MessageFormat.format(msg, new Object[] { property.getResolvedDisplayLabel(), min, max }));
    // add the validation case to the property sheet
    propertySheet.addClientValidation(new ClientValidation("validateStringLength", params, realTimeChecking));
}
Also used : ClientValidation(org.alfresco.web.ui.repo.component.property.UIPropertySheet.ClientValidation) ArrayList(java.util.ArrayList) NumericRangeConstraint(org.alfresco.repo.dictionary.constraint.NumericRangeConstraint) Constraint(org.alfresco.service.cmr.dictionary.Constraint) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) StringLengthConstraint(org.alfresco.repo.dictionary.constraint.StringLengthConstraint) RegexConstraint(org.alfresco.repo.dictionary.constraint.RegexConstraint)

Aggregations

ArrayList (java.util.ArrayList)1 ListOfValuesConstraint (org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint)1 NumericRangeConstraint (org.alfresco.repo.dictionary.constraint.NumericRangeConstraint)1 RegexConstraint (org.alfresco.repo.dictionary.constraint.RegexConstraint)1 StringLengthConstraint (org.alfresco.repo.dictionary.constraint.StringLengthConstraint)1 Constraint (org.alfresco.service.cmr.dictionary.Constraint)1 ClientValidation (org.alfresco.web.ui.repo.component.property.UIPropertySheet.ClientValidation)1