mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Added mandatory validation checks to category/space selectors, association editors and multi value editor
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2677 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
package org.alfresco.web.bean.generator;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.app.servlet.FacesHelper;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.repo.RepoConstants;
|
||||
import org.alfresco.web.ui.repo.component.property.PropertySheetItem;
|
||||
import org.alfresco.web.ui.repo.component.property.UIPropertySheet;
|
||||
import org.alfresco.web.ui.repo.component.property.UIPropertySheet.ClientValidation;
|
||||
|
||||
/**
|
||||
* Generates a component to manage associations.
|
||||
@@ -28,9 +35,29 @@ public class AssociationGenerator extends BaseComponentGenerator
|
||||
protected void setupMandatoryValidation(FacesContext context, UIPropertySheet propertySheet,
|
||||
PropertySheetItem item, UIComponent component, boolean realTimeChecking)
|
||||
{
|
||||
// TODO: the association editor component needs to use the
|
||||
// 'current_value' hidden field rather than the standard
|
||||
// 'value' field as this is always null (it's used internally
|
||||
// by the component) for now disable mandatory checks completely
|
||||
// Override the setup of the mandatory validation as the
|
||||
// [form][element] approach needs to be used to locate the
|
||||
// field and the <comp-id>_current_value hidden field needs
|
||||
// to be used. We also enable real time so the page load
|
||||
// check disables the ok button if necessary, as the user
|
||||
// adds or removes items from the multi value list the
|
||||
// page will be refreshed and therefore re-check the status.
|
||||
|
||||
List<String> params = new ArrayList<String>(3);
|
||||
|
||||
// add the value parameter
|
||||
String value = "document.forms['" +
|
||||
Utils.getParentForm(context, component).getId() + "']['" +
|
||||
component.getClientId(context) + "_current_value'].value";
|
||||
params.add(value);
|
||||
|
||||
// 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");
|
||||
params.add("'" + MessageFormat.format(msg, new Object[] {item.getResolvedDisplayLabel()}) + "'");
|
||||
|
||||
// add the validation case to the property sheet
|
||||
propertySheet.addClientValidation(new ClientValidation("validateMandatory",
|
||||
params, true));
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,19 @@
|
||||
package org.alfresco.web.bean.generator;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.app.servlet.FacesHelper;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.repo.RepoConstants;
|
||||
import org.alfresco.web.ui.repo.component.property.PropertySheetItem;
|
||||
import org.alfresco.web.ui.repo.component.property.UIPropertySheet;
|
||||
import org.alfresco.web.ui.repo.component.property.UIPropertySheet.ClientValidation;
|
||||
|
||||
/**
|
||||
* Generates a category selector component.
|
||||
@@ -37,10 +44,29 @@ public class CategorySelectorGenerator extends BaseComponentGenerator
|
||||
protected void setupMandatoryValidation(FacesContext context, UIPropertySheet propertySheet,
|
||||
PropertySheetItem item, UIComponent component, boolean realTimeChecking)
|
||||
{
|
||||
// TODO: the category selector component needs to use the
|
||||
// 'current_value' hidden field rather than the standard
|
||||
// 'value' field as this is always null (it's used internally
|
||||
// by the component) for now disable mandatory checks completely
|
||||
// Override the setup of the mandatory validation as the
|
||||
// [form][element] approach needs to be used to locate the field
|
||||
// and the <comp-id>_selected hidden field needs to be
|
||||
// used. We also enable real time so the page load check disabled
|
||||
// the ok button if necessary, as the control is used the
|
||||
// page will be refreshed and therefore re-check the status.
|
||||
|
||||
List<String> params = new ArrayList<String>(3);
|
||||
|
||||
// add the value parameter
|
||||
String value = "document.forms['" +
|
||||
Utils.getParentForm(context, component).getId() + "']['" +
|
||||
component.getClientId(context) + "_selected'].value";
|
||||
params.add(value);
|
||||
|
||||
// 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");
|
||||
params.add("'" + MessageFormat.format(msg, new Object[] {item.getResolvedDisplayLabel()}) + "'");
|
||||
|
||||
// add the validation case to the property sheet
|
||||
propertySheet.addClientValidation(new ClientValidation("validateMandatory",
|
||||
params, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,12 +1,19 @@
|
||||
package org.alfresco.web.bean.generator;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.app.servlet.FacesHelper;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.repo.RepoConstants;
|
||||
import org.alfresco.web.ui.repo.component.property.PropertySheetItem;
|
||||
import org.alfresco.web.ui.repo.component.property.UIPropertySheet;
|
||||
import org.alfresco.web.ui.repo.component.property.UIPropertySheet.ClientValidation;
|
||||
|
||||
/**
|
||||
* Generates a component to manage child associations.
|
||||
@@ -28,9 +35,29 @@ public class ChildAssociationGenerator extends BaseComponentGenerator
|
||||
protected void setupMandatoryValidation(FacesContext context, UIPropertySheet propertySheet,
|
||||
PropertySheetItem item, UIComponent component, boolean realTimeChecking)
|
||||
{
|
||||
// TODO: the child assocation editor component needs to use the
|
||||
// 'current_value' hidden field rather than the standard
|
||||
// 'value' field as this is always null (it's used internally
|
||||
// by the component) for now disable mandatory checks completely
|
||||
// Override the setup of the mandatory validation as the
|
||||
// [form][element] approach needs to be used to locate the
|
||||
// field and the <comp-id>_current_value hidden field needs
|
||||
// to be used. We also enable real time so the page load
|
||||
// check disables the ok button if necessary, as the user
|
||||
// adds or removes items from the multi value list the
|
||||
// page will be refreshed and therefore re-check the status.
|
||||
|
||||
List<String> params = new ArrayList<String>(3);
|
||||
|
||||
// add the value parameter
|
||||
String value = "document.forms['" +
|
||||
Utils.getParentForm(context, component).getId() + "']['" +
|
||||
component.getClientId(context) + "_current_value'].value";
|
||||
params.add(value);
|
||||
|
||||
// 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");
|
||||
params.add("'" + MessageFormat.format(msg, new Object[] {item.getResolvedDisplayLabel()}) + "'");
|
||||
|
||||
// add the validation case to the property sheet
|
||||
propertySheet.addClientValidation(new ClientValidation("validateMandatory",
|
||||
params, true));
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,20 @@
|
||||
package org.alfresco.web.bean.generator;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.app.servlet.FacesHelper;
|
||||
import org.alfresco.web.ui.common.ComponentConstants;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.repo.component.UIMultiValueEditor;
|
||||
import org.alfresco.web.ui.repo.component.property.PropertySheetItem;
|
||||
import org.alfresco.web.ui.repo.component.property.UIPropertySheet;
|
||||
import org.alfresco.web.ui.repo.component.property.UIPropertySheet.ClientValidation;
|
||||
|
||||
/**
|
||||
* Generates a text field component.
|
||||
@@ -37,15 +44,30 @@ public class TextFieldGenerator extends BaseComponentGenerator
|
||||
{
|
||||
if (component instanceof UIMultiValueEditor)
|
||||
{
|
||||
// if the text field has multiple values don't allow real time
|
||||
// checking of the mandatory status
|
||||
// Override the setup of the mandatory validation as the
|
||||
// [form][element] approach needs to be used to locate the
|
||||
// field and the <comp-id>_current_value hidden field needs
|
||||
// to be used. We also enable real time so the page load
|
||||
// check disables the ok button if necessary, as the user
|
||||
// adds or removes items from the multi value list the
|
||||
// page will be refreshed and therefore re-check the status.
|
||||
|
||||
// TODO: the multi-value editor component needs to use the
|
||||
// 'current_value' hidden field rather than the standard
|
||||
// 'value' field as this is always null (it's used internally
|
||||
// by the component) for now disable mandatory checks completely
|
||||
List<String> params = new ArrayList<String>(3);
|
||||
|
||||
// add the value parameter
|
||||
String value = "document.forms['" +
|
||||
Utils.getParentForm(context, component).getId() + "']['" +
|
||||
component.getClientId(context) + "_current_value'].value";
|
||||
params.add(value);
|
||||
|
||||
//super.setupMandatoryValidation(context, propertySheet, item, component, false);
|
||||
// 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");
|
||||
params.add("'" + MessageFormat.format(msg, new Object[] {item.getResolvedDisplayLabel()}) + "'");
|
||||
|
||||
// add the validation case to the property sheet
|
||||
propertySheet.addClientValidation(new ClientValidation("validateMandatory",
|
||||
params, true));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user