use of org.alfresco.web.ui.repo.component.UIMultiValueEditor 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.UIMultiValueEditor in project acs-community-packaging by Alfresco.
the class BaseMultiValueRenderer method encodeEnd.
/**
* @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
if (component.isRendered() == false) {
return;
}
if (component instanceof UIMultiValueEditor) {
ResponseWriter out = context.getResponseWriter();
UIMultiValueEditor editor = (UIMultiValueEditor) component;
// get hold of the node service
NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
// render the area between the component and current items list
renderPostWrappedComponent(context, out, editor);
// show the currently selected items
out.write("<tr><td style='padding-top:8px'>");
out.write(editor.getSelectedItemsMsg());
out.write("</td></tr>");
out.write("<tr><td><table cellspacing='0' cellpadding='2' border='0' class='selectedItems'>");
out.write("<tr><td colspan='2' class='selectedItemsHeader'>");
out.write(Application.getMessage(context, "name"));
out.write("</td></tr>");
List currentItems = (List) editor.getValue();
;
if (currentItems != null && currentItems.size() > 0) {
for (int x = 0; x < currentItems.size(); x++) {
Object obj = currentItems.get(x);
if (obj != null) {
if (obj instanceof NodeRef) {
if (nodeService.exists((NodeRef) obj)) {
renderExistingItem(context, component, out, nodeService, x, obj);
} else {
// remove invalid NodeRefs from the list
currentItems.remove(x);
}
} else {
renderExistingItem(context, component, out, nodeService, x, obj);
}
}
}
} else {
out.write("<tr><td class='selectedItemsRow'>");
out.write(editor.getNoSelectedItemsMsg());
out.write("</td></tr>");
}
// close tables
out.write("</table></td></tr></table>\n");
// output a hidden field containing the current value
out.write("<input type='hidden' id='");
out.write(component.getClientId(context));
out.write("_current_value");
out.write("' name='");
out.write(component.getClientId(context));
out.write("_current_value");
out.write("' value='");
if (currentItems != null && currentItems.size() > 0) {
out.write(currentItems.toString());
}
out.write("' />");
}
}
use of org.alfresco.web.ui.repo.component.UIMultiValueEditor in project acs-community-packaging by Alfresco.
the class BaseMultiValueRenderer method encodeBegin.
/**
* @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
*/
@SuppressWarnings("static-access")
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
if (component.isRendered() == false) {
return;
}
// reset the highlighted row flag
this.highlightedRow = false;
if (component instanceof UIMultiValueEditor) {
ResponseWriter out = context.getResponseWriter();
Map attrs = component.getAttributes();
UIMultiValueEditor editor = (UIMultiValueEditor) component;
// start outer table
out.write("<table border='0' cellspacing='3' cellpadding='3'");
this.outputAttribute(out, attrs.get("style"), "style");
this.outputAttribute(out, attrs.get("styleClass"), "class");
out.write(">");
// render the area before the wrapped component
renderPreWrappedComponent(context, out, editor);
}
}
Aggregations