mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +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
|
||||
{
|
||||
|
@@ -392,6 +392,20 @@ public abstract class BaseAssociationEditor extends UIInput
|
||||
|
||||
// close table
|
||||
out.write("</table>");
|
||||
|
||||
// output a hidden field containing the current value
|
||||
out.write("<input type='hidden' name='");
|
||||
out.write(this.getClientId(context));
|
||||
out.write("_current_value");
|
||||
out.write("' value='");
|
||||
// if the current state will leave the node without any associations
|
||||
// do not set a value for the hidden field
|
||||
int numberAssocs = (this.originalAssocs.size() + this.added.size()) - this.removed.size();
|
||||
if (numberAssocs > 0)
|
||||
{
|
||||
out.write(Integer.toString(numberAssocs));
|
||||
}
|
||||
out.write("' />");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,13 +25,10 @@ import javax.faces.component.UIComponent;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.ResponseWriter;
|
||||
import javax.faces.convert.Converter;
|
||||
import javax.faces.convert.DateTimeConverter;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.util.ISO8601DateFormat;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.app.servlet.FacesHelper;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.common.converter.XMLDateConverter;
|
||||
@@ -39,8 +36,6 @@ import org.alfresco.web.ui.common.renderer.BaseRenderer;
|
||||
import org.alfresco.web.ui.repo.RepoConstants;
|
||||
import org.alfresco.web.ui.repo.component.UIMultiValueEditor;
|
||||
import org.alfresco.web.ui.repo.component.UIMultiValueEditor.MultiValueEditorEvent;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Base class for renderers of the MultiValueEditor component.
|
||||
@@ -51,8 +46,6 @@ import org.apache.commons.logging.LogFactory;
|
||||
*/
|
||||
public abstract class BaseMultiValueRenderer extends BaseRenderer
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(BaseMultiValueRenderer.class);
|
||||
|
||||
/** I18N message strings */
|
||||
protected final static String MSG_REMOVE = "remove";
|
||||
protected final static String MSG_SELECT_BUTTON = "select_button";
|
||||
@@ -68,10 +61,7 @@ public abstract class BaseMultiValueRenderer extends BaseRenderer
|
||||
*/
|
||||
public void decode(FacesContext context, UIComponent component)
|
||||
{
|
||||
Object obj = FacesHelper.getManagedBean(context, "MultiValueEditorBean");
|
||||
|
||||
Map requestMap = context.getExternalContext().getRequestParameterMap();
|
||||
Map valuesMap = context.getExternalContext().getRequestParameterValuesMap();
|
||||
String fieldId = getHiddenFieldName(component);
|
||||
String value = (String)requestMap.get(fieldId);
|
||||
|
||||
@@ -104,6 +94,7 @@ public abstract class BaseMultiValueRenderer extends BaseRenderer
|
||||
/**
|
||||
* @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)
|
||||
@@ -118,7 +109,6 @@ public abstract class BaseMultiValueRenderer extends BaseRenderer
|
||||
{
|
||||
ResponseWriter out = context.getResponseWriter();
|
||||
Map attrs = component.getAttributes();
|
||||
String clientId = component.getClientId(context);
|
||||
UIMultiValueEditor editor = (UIMultiValueEditor)component;
|
||||
|
||||
// start outer table
|
||||
@@ -137,6 +127,11 @@ public abstract class BaseMultiValueRenderer extends BaseRenderer
|
||||
*/
|
||||
public void encodeEnd(FacesContext context, UIComponent component) throws IOException
|
||||
{
|
||||
if (component.isRendered() == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (component instanceof UIMultiValueEditor)
|
||||
{
|
||||
ResponseWriter out = context.getResponseWriter();
|
||||
@@ -193,7 +188,18 @@ public abstract class BaseMultiValueRenderer extends BaseRenderer
|
||||
}
|
||||
|
||||
// close tables
|
||||
out.write("</table></td></tr></table>");
|
||||
out.write("</table></td></tr></table>\n");
|
||||
|
||||
// output a hidden field containing the current value
|
||||
out.write("<input type='hidden' 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("' />");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package org.alfresco.web.ui.repo.renderer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.ResponseWriter;
|
||||
|
Reference in New Issue
Block a user