use of org.alfresco.web.ui.repo.component.property.UIPropertySheet.ClientValidation in project acs-community-packaging by Alfresco.
the class BaseComponentGenerator method setupRegexConstraint.
/**
* Sets up a default validation rule for the regular expression 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 setupRegexConstraint(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem property, UIComponent component, RegexConstraint constraint, boolean realTimeChecking) {
String expression = constraint.getExpression();
boolean requiresMatch = constraint.getRequiresMatch();
List<String> params = new ArrayList<String>(3);
// add the value parameter
String value = "document.getElementById('" + component.getClientId(context) + (component instanceof UIMultiValueEditor ? "_current_value" : "") + "')";
params.add(value);
// add the regular expression parameter
try {
// encode the expression so it can be unescaped by JavaScript
addStringConstraintParam(params, URLEncoder.encode(expression, "UTF-8"));
} catch (UnsupportedEncodingException e) {
// just add the expression as is
addStringConstraintParam(params, expression);
}
// add the requiresMatch parameter
params.add(Boolean.toString(requiresMatch));
// add the validation failed messages
String matchMsg = Application.getMessage(context, "validation_regex");
addStringConstraintParam(params, MessageFormat.format(matchMsg, new Object[] { property.getResolvedDisplayLabel() }));
String noMatchMsg = Application.getMessage(context, "validation_regex_not_match");
addStringConstraintParam(params, MessageFormat.format(noMatchMsg, new Object[] { property.getResolvedDisplayLabel() }));
// add the validation case to the property sheet
propertySheet.addClientValidation(new ClientValidation((component instanceof UIMultiValueEditor ? "validateMultivalueRegex" : "validateRegex"), params, realTimeChecking));
}
use of org.alfresco.web.ui.repo.component.property.UIPropertySheet.ClientValidation 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));
}
use of org.alfresco.web.ui.repo.component.property.UIPropertySheet.ClientValidation in project acs-community-packaging by Alfresco.
the class BaseComponentGenerator method setupNumericRangeConstraint.
/**
* Sets up a default validation rule for the numeric range 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 setupNumericRangeConstraint(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem property, UIComponent component, NumericRangeConstraint constraint, boolean realTimeChecking) {
double min = constraint.getMinValue();
double max = constraint.getMaxValue();
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(Double.toString(min));
// add the max parameter
params.add(Double.toString(max));
// add the validation failed message to show
String msg = Application.getMessage(context, "validation_numeric_range");
addStringConstraintParam(params, MessageFormat.format(msg, new Object[] { property.getResolvedDisplayLabel(), min, max }));
// add the validation case to the property sheet
propertySheet.addClientValidation(new ClientValidation("validateNumberRange", params, false));
}
use of org.alfresco.web.ui.repo.component.property.UIPropertySheet.ClientValidation in project acs-community-packaging by Alfresco.
the class BaseComponentGenerator method setupMandatoryValidation.
/**
* Sets up a client mandatory validation rule with the property
* sheet for the given item.
*
* @param context FacesContext
* @param propertySheet The property sheet to add the validation rule to
* @param item The item being generated
* @param component The component representing the item
* @param realTimeChecking true to make the client validate as the user types
* @param idSuffix An optional suffix to add to the client id
*/
protected void setupMandatoryValidation(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem item, UIComponent component, boolean realTimeChecking, String idSuffix) {
List<String> params = new ArrayList<String>(3);
// add the value parameter
StringBuilder value = new StringBuilder("document.getElementById('");
value.append(component.getClientId(context));
if (idSuffix != null) {
value.append(idSuffix);
}
value.append("')");
params.add(value.toString());
// add the validation failed message to show (use the value of the
// label component of the given item)
String msg = Application.getMessage(context, "validation_mandatory");
addStringConstraintParam(params, MessageFormat.format(msg, new Object[] { item.getResolvedDisplayLabel() }));
// add the validation case to the property sheet
propertySheet.addClientValidation(new ClientValidation("validateMandatory", params, realTimeChecking));
}
use of org.alfresco.web.ui.repo.component.property.UIPropertySheet.ClientValidation in project acs-community-packaging by Alfresco.
the class TextFieldGenerator method setupConstraints.
@Override
@SuppressWarnings("unchecked")
protected void setupConstraints(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem property, PropertyDefinition propertyDef, UIComponent component) {
// do the default processing first
super.setupConstraints(context, propertySheet, property, propertyDef, component);
// validateIsNumber validation function
if (propertySheet.inEditMode() && propertySheet.isValidationEnabled() && propertyDef != null) {
// check the type of the property is a number
if (propertyDef.getDataType().getName().equals(DataTypeDefinition.DOUBLE) || propertyDef.getDataType().getName().equals(DataTypeDefinition.FLOAT) || propertyDef.getDataType().getName().equals(DataTypeDefinition.INT) || propertyDef.getDataType().getName().equals(DataTypeDefinition.LONG)) {
List<String> params = new ArrayList<String>(3);
// add the value parameter
String value = "document.getElementById('" + component.getClientId(context) + "')";
params.add(value);
// add the validation failed message to show
String msg = Application.getMessage(context, "validation_is_number");
addStringConstraintParam(params, MessageFormat.format(msg, new Object[] { property.getResolvedDisplayLabel() }));
// add the validation case to the property sheet
propertySheet.addClientValidation(new ClientValidation("validateIsNumber", params, false));
}
}
}
Aggregations