Author: sylvain Date: Tue Nov 2 02:34:54 2004 New Revision: 56365 Added: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetState.java (contents, props changed) Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/ScriptableWidget.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v3/ScriptableWidget.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Struct.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/dreamteam/flow/team.js cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_form.xml cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-advanced-field-styling.xsl cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-calendar-styling.xsl cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/sitemap.xmap cocoon/branches/BRANCH_2_1_X/status.xml Log: added widget states
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/ScriptableWidget.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/ScriptableWidget.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/ScriptableWidget.java Tue Nov 2 02:34:54 2004 @@ -22,6 +22,7 @@ import org.apache.cocoon.forms.formmodel.Output; import org.apache.cocoon.forms.formmodel.Repeater; import org.apache.cocoon.forms.formmodel.Widget; +import org.apache.cocoon.forms.formmodel.WidgetState; import org.mozilla.javascript.Context; import org.mozilla.javascript.NativeArray; import org.mozilla.javascript.Scriptable; @@ -30,7 +31,7 @@ import org.mozilla.javascript.Wrapper; /** - * @version $Id: ScriptableWidget.java,v 1.5 2004/05/07 22:04:20 joerg Exp $ + * @version $Id$ * */ public class ScriptableWidget extends ScriptableObject { @@ -275,6 +276,27 @@ public String jsGet_id() { return delegate.getId(); + } + + public WidgetState jsGet_state() { + return delegate.getState(); + } + + public void jsSet_state(Object stateObj) { + Object obj = unwrap(stateObj); + WidgetState state = null; + + if (obj instanceof String) { + state = WidgetState.stateForName((String)obj); + } else if (obj instanceof WidgetState) { + state = (WidgetState)obj; + } + + if (state == null) { + throw new IllegalArgumentException("Invalid value for widgetState " + stateObj); + } + + delegate.setState(state); } public Scriptable jsGet_parent() { Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java Tue Nov 2 02:34:54 2004 @@ -35,12 +35,14 @@ import org.apache.cocoon.forms.formmodel.Submit; import org.apache.cocoon.forms.formmodel.Upload; import org.apache.cocoon.forms.formmodel.Widget; +import org.apache.cocoon.forms.formmodel.WidgetState; import org.apache.cocoon.forms.validation.ValidationError; import org.apache.cocoon.forms.validation.ValidationErrorAware; import org.mozilla.javascript.Context; import org.mozilla.javascript.JavaScriptException; import org.mozilla.javascript.NativeArray; import org.mozilla.javascript.Function; +import org.mozilla.javascript.NativeJavaObject; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.Undefined; @@ -53,7 +55,7 @@ import java.util.HashMap; /** - * @version $Id: ScriptableWidget.java,v 1.12 2004/05/11 09:30:24 mpo Exp $ + * @version $Id$ * */ public class ScriptableWidget extends ScriptableObject { @@ -459,6 +461,27 @@ public String jsFunction_getId() { return delegate.getId(); + } + + public WidgetState jsGet_state() { + return delegate.getState(); + } + + public void jsSet_state(Object stateObj) { + Object obj = unwrap(stateObj); + WidgetState state = null; + + if (obj instanceof String) { + state = WidgetState.stateForName((String)obj); + } else if (obj instanceof WidgetState) { + state = (WidgetState)obj; + } + + if (state == null) { + throw new IllegalArgumentException("Invalid value for widgetState " + stateObj); + } + + delegate.setState(state); } public ScriptableWidget jsFunction_getSubmitWidget() { Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v3/ScriptableWidget.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v3/ScriptableWidget.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v3/ScriptableWidget.java Tue Nov 2 02:34:54 2004 @@ -32,6 +32,7 @@ import org.apache.cocoon.forms.formmodel.Submit; import org.apache.cocoon.forms.formmodel.Upload; import org.apache.cocoon.forms.formmodel.Widget; +import org.apache.cocoon.forms.formmodel.WidgetState; import org.apache.cocoon.forms.validation.ValidationError; import org.apache.cocoon.forms.validation.ValidationErrorAware; import org.apache.cocoon.forms.validation.WidgetValidator; @@ -51,7 +52,7 @@ import java.util.HashMap; /** - * @version $Id: ScriptableWidget.java,v 1.4 2004/05/08 11:27:54 bruno Exp $ + * @version $Id$ * */ public class ScriptableWidget extends ScriptableObject implements ValueChangedListener, ActionListener, WidgetValidator { @@ -450,6 +451,27 @@ public String jsFunction_getId() { return delegate.getId(); + } + + public WidgetState jsGet_state() { + return delegate.getState(); + } + + public void jsSet_state(Object stateObj) { + Object obj = unwrap(stateObj); + WidgetState state = null; + + if (obj instanceof String) { + state = WidgetState.stateForName((String)obj); + } else if (obj instanceof WidgetState) { + state = (WidgetState)obj; + } + + if (state == null) { + throw new IllegalArgumentException("Invalid value for widgetState " + stateObj); + } + + delegate.setState(state); } public ScriptableWidget jsFunction_getSubmitWidget() { Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java Tue Nov 2 02:34:54 2004 @@ -37,7 +37,8 @@ /** * Constructs AbstractContainerWidget */ - public AbstractContainerWidget() { + public AbstractContainerWidget(AbstractWidgetDefinition definition) { + super(definition); widgets = new WidgetList(); } @@ -70,7 +71,9 @@ * of the contained widgets. */ public void readFromRequest(FormContext formContext) { - widgets.readFromRequest(formContext); + if (getCombinedState().isAcceptingInputs()) { + widgets.readFromRequest(formContext); + } } /** @@ -85,6 +88,9 @@ * extra validation rules on this containment level are ok. */ public boolean validate() { + if (!getCombinedState().isAcceptingInputs()) + return true; + // Validate children first, then always validate self. Return combined result. final boolean valid = widgets.validate(); return super.validate() && valid; @@ -100,6 +106,8 @@ * @throws SAXException */ public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { - widgets.generateSaxFragment(contentHandler, locale); + if (getCombinedState().isDisplayingValues()) { + widgets.generateSaxFragment(contentHandler, locale); + } } } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java Tue Nov 2 02:34:54 2004 @@ -45,6 +45,11 @@ private Widget parent; /** + * The widget's own state + */ + private WidgetState state = WidgetState.ACTIVE; + + /** * Lazy loaded reference to the top-level form. */ private Form form; @@ -58,7 +63,10 @@ * Storage for the widget allocated attributes */ private Map attributes; - + + protected AbstractWidget(AbstractWidgetDefinition definition) { + this.state = definition.getState(); + } /** * Gets the id of this widget. @@ -92,7 +100,8 @@ /** * @return The parent-widget of this widget. */ - public Widget getParent() { + // This method is final in order for other methods in this class to use this.parent + public final Widget getParent() { return parent; } @@ -123,6 +132,25 @@ return this.form; } + public WidgetState getState() { + return this.state; + } + + public void setState(WidgetState state) { + if (state == null) { + throw new IllegalArgumentException("A widget state cannot be set to null"); + } + this.state = state; + } + + public WidgetState getCombinedState() { + if (parent == null) { + return this.state; + } else { + return WidgetState.strictest(this.state, parent.getCombinedState()); + } + } + public String getRequestParameterName() { Widget myParent = getParent(); if (myParent != null) { @@ -231,8 +259,13 @@ } } - public boolean validate() { + + // Consider widget valid if it doesn't accept user inputs + if (!getCombinedState().isAcceptingInputs()) { + return true; + } + // Test validators from the widget definition if (!getDefinition().validate(this)) { // Failed @@ -270,7 +303,9 @@ * @throws SAXException */ public void generateLabel(ContentHandler contentHandler) throws SAXException { - getDefinition().generateDisplayData("label", contentHandler); + if (getCombinedState().isDisplayingValues()) { + getDefinition().generateDisplayData("label", contentHandler); + } } @@ -285,7 +320,7 @@ * @param locale in which context potential content needs to be put. * @throws SAXException */ - public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { + protected void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { // Do nothing } @@ -295,7 +330,7 @@ * * @return the main elementname for this widget's sax-fragment. */ - public abstract String getXMLElementName(); + protected abstract String getXMLElementName(); /** * The XML attributes used in [EMAIL PROTECTED] #generateSaxFragment(ContentHandler, Locale)} @@ -311,13 +346,19 @@ * * @return the attributes for the main element for this widget's sax-fragment. */ - public AttributesImpl getXMLElementAttributes() { + protected AttributesImpl getXMLElementAttributes() { AttributesImpl attrs = new AttributesImpl(); // top-level widget-containers like forms will have their id set to "" // for those the @id should not be included. if (getId().length() != 0) { attrs.addCDATAAttribute("id", getRequestParameterName()); } + + // Add the "state" attribute is different from active (the default state) + WidgetState state = getCombinedState(); + if (state != WidgetState.ACTIVE) { + attrs.addCDATAAttribute("state", getCombinedState().getName()); + } return attrs; } @@ -333,7 +374,7 @@ * * @see WidgetDefinition#generateDisplayData(ContentHandler) */ - public void generateDisplayData(ContentHandler contentHandler) throws SAXException { + protected void generateDisplayData(ContentHandler contentHandler) throws SAXException { getDefinition().generateDisplayData(contentHandler); } @@ -360,15 +401,18 @@ */ public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { - String element = this.getXMLElementName(); - AttributesImpl attrs = getXMLElementAttributes(); - contentHandler.startElement(Constants.INSTANCE_NS, element, Constants.INSTANCE_PREFIX_COLON + element, attrs); - - generateDisplayData(contentHandler); - - generateItemSaxFragment(contentHandler, locale); - - contentHandler.endElement(Constants.INSTANCE_NS, element, Constants.INSTANCE_PREFIX_COLON + element); + if (getCombinedState().isDisplayingValues()) { + + String element = this.getXMLElementName(); + AttributesImpl attrs = getXMLElementAttributes(); + contentHandler.startElement(Constants.INSTANCE_NS, element, Constants.INSTANCE_PREFIX_COLON + element, attrs); + + generateDisplayData(contentHandler); + + generateItemSaxFragment(contentHandler, locale); + + contentHandler.endElement(Constants.INSTANCE_NS, element, Constants.INSTANCE_PREFIX_COLON + element); + } } public Object getAttribute(String name) { Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java Tue Nov 2 02:34:54 2004 @@ -46,6 +46,7 @@ private Map attributes; private Map displayData; private List validators; + private WidgetState state = WidgetState.ACTIVE; protected CreateListener createListener; @@ -74,7 +75,15 @@ public WidgetDefinition getParent() { return this.parent; } + + public WidgetState getState() { + return this.state; + } + public void setState(WidgetState state) { + this.state = state; + } + protected void setLocation(String location) { this.location = location; } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java Tue Nov 2 02:34:54 2004 @@ -81,6 +81,17 @@ widgetDefinition.setId(id); } + // state + String stateValue = DomHelper.getAttribute(widgetElement, "state", null); + if (stateValue != null) { + WidgetState state = WidgetState.stateForName(stateValue); + if (state == null) { + throw new Exception ("Unknow value '" + stateValue +"' for state attribute at " + + DomHelper.getLocation(widgetElement)); + } + widgetDefinition.setState(state); + } + // attributes Element attrContainer = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS, "attributes", false); if (attrContainer != null) { Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java Tue Nov 2 02:34:54 2004 @@ -28,7 +28,7 @@ * ActionEvent when a requestparameter is present with as name the id of this Action widget, and as * value a non-empty value. * - * @version $Id: Action.java,v 1.10 2004/05/07 13:42:09 mpo Exp $ + * @version $Id$ */ public class Action extends AbstractWidget implements ActionListenerEnabled { private final ActionDefinition definition; @@ -36,6 +36,7 @@ private ActionListener listener; public Action(ActionDefinition definition) { + super(definition); this.definition = definition; } @@ -44,6 +45,9 @@ } public void readFromRequest(final FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + Form form = getForm(); // Set the submit widget if we can determine it from the request Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java Tue Nov 2 02:34:54 2004 @@ -95,6 +95,9 @@ } public void readFromRequest(FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + String newEnteredValue = formContext.getRequest().getParameter(getRequestParameterName()); if (newEnteredValue != null) { // There is one aggregated entered value. Read it and split it. @@ -187,6 +190,9 @@ } public boolean validate() { + if (!getCombinedState().isAcceptingInputs()) + return true; + if (enteredValue != null && !fieldsHaveValues()) { XMLizable failMessage = getAggregateFieldDefinition().getSplitFailMessage(); if (failMessage != null) { Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java Tue Nov 2 02:34:54 2004 @@ -51,6 +51,7 @@ protected ValidationError validationError; public BooleanField(BooleanFieldDefinition definition) { + super(definition); this.definition = definition; } @@ -59,6 +60,9 @@ } public void readFromRequest(FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + validationError = null; Object oldValue = value; String param = formContext.getRequest().getParameter(getRequestParameterName()); Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java Tue Nov 2 02:34:54 2004 @@ -112,6 +112,7 @@ public Field(FieldDefinition fieldDefinition) { + super(fieldDefinition); this.fieldDefinition = fieldDefinition; } @@ -170,6 +171,9 @@ } public void readFromRequest(FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + String newEnteredValue = formContext.getRequest().getParameter(getRequestParameterName()); // FIXME: Should we consider only non-null values, which allows to // split a form across several screens? @@ -205,6 +209,9 @@ } public boolean validate() { + if (!getCombinedState().isAcceptingInputs()) + return true; + if (this.valueState == VALUE_UNPARSED) { doParse(); } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java Tue Nov 2 02:34:54 2004 @@ -53,6 +53,7 @@ private CursorableLinkedList events; public Form(FormDefinition definition) { + super(definition); this.definition = definition; } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java Tue Nov 2 02:34:54 2004 @@ -34,7 +34,7 @@ * <p>This widget is typically used to communicate extra validation errors or other messages * to the user, that aren't associated with any other widget in particular. * - * @version $Id: Messages.java,v 1.8 2004/04/30 12:19:01 bruno Exp $ + * @version $Id$ */ public class Messages extends AbstractWidget { private ArrayList messages = new ArrayList(); @@ -44,6 +44,7 @@ private static final String MESSAGE_EL = "message"; protected Messages(MessagesDefinition definition) { + super(definition); this.definition = definition; } @@ -52,11 +53,16 @@ } public void readFromRequest(FormContext formContext) { - messages.clear(); + if (getCombinedState().isAcceptingInputs()) { + messages.clear(); + } } public boolean validate() { - return messages.size() == 0; + if (!getCombinedState().isAcceptingInputs()) + return true; + else + return messages.size() == 0; } /** Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java Tue Nov 2 02:34:54 2004 @@ -58,6 +58,7 @@ private ValidationError validationError; public MultiValueField(MultiValueFieldDefinition definition) { + super(definition); this.definition = definition; } @@ -66,6 +67,9 @@ } public void readFromRequest(FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + enteredValues = formContext.getRequest().getParameterValues(getRequestParameterName()); validationError = null; values = null; @@ -99,6 +103,9 @@ } public boolean validate() { + if (!getCombinedState().isAcceptingInputs()) + return true; + if (values != null) validationError = definition.getDatatype().validate(values, new ExpressionContextImpl(this)); else Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java Tue Nov 2 02:34:54 2004 @@ -31,7 +31,7 @@ * * <p>An Output widget is always valid and never required. * - * @version $Id: Output.java,v 1.9 2004/05/07 13:42:09 mpo Exp $ + * @version $Id$ */ public class Output extends AbstractWidget implements DataWidget { @@ -47,6 +47,7 @@ } protected Output(OutputDefinition definition) { + super(definition); this.definition = definition; } @@ -73,7 +74,7 @@ return OUTPUT_EL; } - public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { + protected void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { // the value if (value != null) { contentHandler.startElement(Constants.INSTANCE_NS, VALUE_EL, Constants.INSTANCE_PREFIX_COLON + VALUE_EL, XMLUtils.EMPTY_ATTRIBUTES); Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java Tue Nov 2 02:34:54 2004 @@ -48,6 +48,7 @@ private final List rows = new ArrayList(); public Repeater(RepeaterDefinition repeaterDefinition) { + super(repeaterDefinition); this.definition = repeaterDefinition; // setup initial size removeRows(); @@ -179,6 +180,9 @@ } public void readFromRequest(FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + // read number of rows from request, and make an according number of rows String sizeParameter = formContext.getRequest().getParameter(getRequestParameterName() + ".size"); if (sizeParameter != null) { @@ -215,6 +219,9 @@ } public boolean validate() { + if (!getCombinedState().isAcceptingInputs()) + return true; + boolean valid = true; Iterator rowIt = rows.iterator(); while (rowIt.hasNext()) { @@ -303,6 +310,8 @@ public class RepeaterRow extends AbstractContainerWidget { public RepeaterRow(AbstractWidgetDefinition definition) { + super(definition); + setParent(Repeater.this); ((ContainerDefinition)definition).createWidgets(this); } @@ -319,10 +328,6 @@ return String.valueOf(rows.indexOf(this)); } - public Widget getParent() { - return Repeater.this; - } - public Form getForm() { return Repeater.this.getForm(); } @@ -334,10 +339,6 @@ // public String getFullyQualifiedId() { // return getParent().getNamespace() + "." + getId(); // } - - public void setParent(Widget widget) { - throw new RuntimeException("Parent of RepeaterRow is fixed, and cannot be set."); - } public boolean validate() { // Validate only child widtgets, as the definition's validators are those of the parent repeater Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Struct.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Struct.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Struct.java Tue Nov 2 02:34:54 2004 @@ -19,7 +19,7 @@ /** * A container [EMAIL PROTECTED] Widget} which can hold zero or more child widgets. * - * @version $Id: Struct.java,v 1.4 2004/04/20 22:19:27 mpo Exp $ + * @version $Id$ */ public class Struct extends AbstractContainerWidget { private static final String STRUCT_EL = "struct"; @@ -27,6 +27,7 @@ private final StructDefinition definition; public Struct(StructDefinition definition) { + super(definition); this.definition = definition; } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java Tue Nov 2 02:34:54 2004 @@ -37,6 +37,7 @@ private final UnionDefinition definition; public Union(UnionDefinition definition) { + super(definition); this.definition = definition; // TODO: Remove after moving logic to Field. //item.enteredValue = (String)definition.getDefaultValue(); @@ -74,6 +75,9 @@ } public void readFromRequest(FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + // Ensure the case widget has read its value caseWidget.readFromRequest(formContext); @@ -101,6 +105,9 @@ // TODO: Simplify this logic. public boolean validate() { + if (!getCombinedState().isAcceptingInputs()) + return true; + Widget widget; boolean valid = true; // Read current case from request Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java Tue Nov 2 02:34:54 2004 @@ -43,6 +43,7 @@ private ValidationError validationError; public Upload(UploadDefinition uploadDefinition) { + super(uploadDefinition); this.uploadDefinition = uploadDefinition; } @@ -67,6 +68,9 @@ } public void readFromRequest(FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + Object obj = formContext.getRequest().get(getRequestParameterName()); // If the request object is a Part, keep it @@ -97,6 +101,9 @@ } public boolean validate() { + if (!getCombinedState().isAcceptingInputs()) + return true; + if (this.part == null) { if (this.uploadDefinition.isRequired()) { this.validationError = new ValidationError(new I18nMessage("general.field-required", Constants.I18N_CATALOGUE)); Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java Tue Nov 2 02:34:54 2004 @@ -49,7 +49,7 @@ * keeps the Widgets small and light to create. This mechanism is similar to * classes and objects in Java. * - * @version CVS $Id: Widget.java,v 1.15 2004/05/11 12:55:53 vgritsenko Exp $ + * @version CVS $Id$ */ public interface Widget { @@ -88,7 +88,34 @@ * of the widget. */ public Form getForm(); - + + /** + * Get the widget's own state. Note that this state is <em>not</em> the one actually considered + * for handling requests and producing output. For these matters, the combined state is used. + * + * @see #getCombinedState() + * @return the widget's own state + */ + public WidgetState getState(); + + /** + * Set the widget's own state. This may change its combined state, and those of its + * children, if any. + * + * @param state the new wiget state + */ + public void setState(WidgetState state); + + /** + * Get the widget's combined state, which is the strictest of its own state and parent state. + * This combined state is the one that will be used by the widget to know if request + * parameters should be considered and if some output must be produced. + * + * @see WidgetState#strictest(WidgetState, WidgetState) + * @return the combined state + */ + public WidgetState getCombinedState(); + /** * @return the id prefixed with the namespace, this name should be unique * accross all widgets on the form. Added: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetState.java ============================================================================== --- (empty file) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetState.java Tue Nov 2 02:34:54 2004 @@ -0,0 +1,130 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.forms.formmodel; + +import org.apache.commons.lang.enums.ValuedEnum; + +/** + * The state of a widget. States are ordered from the most featured ("active") + * to the most constrained ("invisible"), so that state combinations can be + * computed: a widget's combined state is the strictest between the widget's own + * state and its parent state. + * + * @version CVS $Id$ + */ +public class WidgetState extends ValuedEnum { + + private static final int ACTIVE_VALUE = 3; + + private static final int DISABLED_VALUE = 2; + + private static final int INVISIBLE_VALUE = 1; + + /** + * Active state. This is the default state, where widgets read their values + * from the request and display them. + */ + public static final WidgetState ACTIVE = new WidgetState("active", ACTIVE_VALUE); + + /** + * Disabled state. Values are displayed, but user input is ignored. + */ + public static final WidgetState DISABLED = new WidgetState("disabled", DISABLED_VALUE); + + /** + * Invisible state. Values are not displayed and user input is ignored. + */ + public static final WidgetState INVISIBLE = new WidgetState("invisible", INVISIBLE_VALUE); + + /** + * Private constructor + */ + private WidgetState(String name, int value) { + super(name, value); + } + + /** + * Get a state given its name. Valid names are "active", "disabled", + * "invisible". + * + * @param name the state name + * @return the state, or <code>null</code> if <code>name</code> doesn't + * denote a known state name + */ + public static WidgetState stateForName(String name) { + return (WidgetState) getEnum(WidgetState.class, name); + } + + /** + * Determine the strictest of two states. "invisible" is stricter than + * "disabled" which is stricter than "active" + * + * @param one a state + * @param two another state + * @return the strictes of <code>one</code> and <code>two</code> + */ + public static WidgetState strictest(WidgetState one, WidgetState two) { + return (one.getValue() < two.getValue()) ? one : two; + } + + /** + * Test if the current state is stricter than another one. + * + * @param other a state + * @return <code>true</code> if <code>this</code> is stricter + * than <code>other</code> + */ + public boolean stricterThan(WidgetState other) { + return this.getValue() < other.getValue(); + } + + /** + * Does this state accept user inputs? + * + * @return <code>true</code> if this state accepts user inputs. + */ + public boolean isAcceptingInputs() { + return this.getValue() == ACTIVE_VALUE; + } + + /** + * Does this state display widget values? + * + * @return <code>true</code> if this state displays widget values. + */ + public boolean isDisplayingValues() { + return this.getValue() > INVISIBLE_VALUE; + } + +// Potential features provided by ValuedEnum that don't seem to be needed now +// +// public static WidgetState stateForValue(int stateValue) { +// return (WidgetState) getEnum(WidgetState.class, stateValue); +// } +// +// public static Map getEnumMap() { +// return getEnumMap(WidgetState.class); +// } +// +// public static List getStateList() { +// return getEnumList(WidgetState.class); +// } +// +// public static Iterator iterator() { +// return iterator(WidgetState.class); +// } + +} \ No newline at end of file Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java Tue Nov 2 02:34:54 2004 @@ -59,7 +59,7 @@ this.cocoonConsumer = consumer; } - public void startForm(Map attributes) throws SAXException { + public void startForm(Form form, Map attributes) throws SAXException { // build attributes AttributesImpl attrs = new AttributesImpl(); Iterator iter = attributes.entrySet().iterator(); @@ -187,6 +187,10 @@ public boolean isSelectedCase(Widget unionWidget, String caseValue) { String value = (String)unionWidget.getValue(); return caseValue.equals(value != null ? value : ""); + } + + public boolean isVisible(Widget widget) { + return widget.getCombinedState().isDisplayingValues(); } /** Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml Tue Nov 2 02:34:54 2004 @@ -7,12 +7,14 @@ --> <jx:macro name="form-template" targetNamespace="http://apache.org/cocoon/forms/1.0#template"> <jx:set var="cformsHelper" value="${Packages.org.apache.cocoon.forms.generation.JXMacrosHelper.createHelper(cocoon.consumer)}"/> - <jx:set var="cformsDummy" value="${cformsHelper.startForm(macro.arguments)}"/> - <jx:set var="form" value="${CocoonFormsInstance}"/> + <jx:set var="form" value="${CocoonFormsInstance}"/> + <jx:if test="${cformsHelper.isVisible(form)}"> + <jx:set var="cformsDummy" value="${cformsHelper.startForm(form, macro.arguments)}"/> <!-- the form is also the current widget --> <jx:set var="widget" value="${form}"/> <jx:evalBody/> - <jx:set var="cformsDummy" value="${cformsHelper.endForm()}"/> + <jx:set var="cformsDummy" value="${cformsHelper.endForm()}"/> + </jx:if> </jx:macro> <!-- @@ -21,10 +23,12 @@ <jx:macro name="widget" targetNamespace="http://apache.org/cocoon/forms/1.0#template"> <jx:parameter name="id"/> - <jx:set var="widget" value="${cformsHelper.getWidget(widget, id)}"/> - <jx:set var="cformsDummy" value="${cformsHelper.generateWidget(widget, locale)}"/> - <jx:evalBody/> - <jx:set var="cformsDummy" value="${cformsHelper.flushRoot(widget)}"/> + <jx:set var="widget" value="${cformsHelper.getWidget(widget, id)}"/> + <jx:if test="${cformsHelper.isVisible(widget)}"> + <jx:set var="cformsDummy" value="${cformsHelper.generateWidget(widget, locale)}"/> + <jx:evalBody/> + <jx:set var="cformsDummy" value="${cformsHelper.flushRoot(widget)}"/> + </jx:if> </jx:macro> <!-- @@ -61,11 +65,15 @@ <jx:macro name="repeater-widget" targetNamespace="http://apache.org/cocoon/forms/1.0#template"> <jx:parameter name="id"/> - <jx:set var="repeater" value="${cformsHelper.getRepeater(widget, id)}"/> - <jx:forEach varStatus="repeaterLoop" begin="0" end="${repeater.getSize() - 1}"> - <jx:set var="widget" value="${repeater.getRow(repeaterLoop.index)}"/> - <jx:evalBody/> - </jx:forEach> + <jx:set var="repeater" value="${cformsHelper.getRepeater(widget, id)}"/> + <jx:if test="${cformsHelper.isVisible(repeater)}"> + <jx:forEach varStatus="repeaterLoop" begin="0" end="${repeater.getSize() - 1}"> + <jx:set var="widget" value="${repeater.getRow(repeaterLoop.index)}"/> + <jx:if test="${cformsHelper.isVisible(widget)}"> + <jx:evalBody/> + </jx:if> + </jx:forEach> + </jx:if> </jx:macro> <!-- @@ -100,9 +108,11 @@ <jx:parameter name="id"/> <jx:set var="widget" value="${cformsHelper.getWidget(widget, id)}"/> - <fi:struct id="${widget.getRequestParameterName()}"> - <jx:evalBody/> - </fi:struct> + <jx:if test="${cformsHelper.isVisible(widget)}"> + <fi:struct id="${widget.getRequestParameterName()}"> + <jx:evalBody/> + </fi:struct> + </jx:if> </jx:macro> <!-- @@ -112,9 +122,11 @@ <jx:parameter name="id"/> <jx:set var="widget" value="${cformsHelper.getWidget(widget, id)}"/> - <fi:union id="${widget.getRequestParameterName()}"> - <jx:evalBody/> - </fi:union> + <jx:if test="${cformsHelper.isVisible(widget)}"> + <fi:union id="${widget.getRequestParameterName()}"> + <jx:evalBody/> + </fi:union> + </jx:if> </jx:macro> <!-- @@ -152,7 +164,9 @@ <jx:parameter name="id"/> <jx:set var="widget" value="${cformsHelper.getWidget(widget, id)}"/> - <jx:evalBody/> + <jx:if test="${cformsHelper.isVisible(widget)}"> + <jx:evalBody/> + </jx:if> </jx:macro> </jx:template> Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java Tue Nov 2 02:34:54 2004 @@ -187,6 +187,10 @@ throwWrongWidgetType("RepeaterWidgetLabelHandler", input.loc, "repeater"); } } + + protected boolean isVisible(Widget widget) { + return widget.getCombinedState().isDisplayingValues(); + } public void throwWrongWidgetType(String pipeName, String element, String widget) throws SAXException { throwSAXException(pipeName + ": Element \"" + element + "\" can only be used for " + widget + " widgets."); @@ -276,7 +280,6 @@ if (contextWidget != null) { throwSAXException("Detected nested wt:form-template elements, this is not allowed."); } - out.startPrefixMapping(Constants.INSTANCE_PREFIX, Constants.INSTANCE_NS); // ====> Retrieve the form // First look for the form using the location attribute, if any @@ -286,6 +289,11 @@ input.removeAttribute(LOCATION); } contextWidget = pipeContext.findForm(formJXPath); + + if (!isVisible(contextWidget)) { + // Skip widget and its content + return nullHandler; + } // ====> Determine the Locale //TODO pull this locale stuff also up in the Config object? @@ -311,6 +319,8 @@ } } + out.startPrefixMapping(Constants.INSTANCE_PREFIX, Constants.INSTANCE_NS); + // we need to merge input.attrs with possible overruling attributes // from the pipeContext input.addAttributes(pipeContext.getFormAttributes()); @@ -372,10 +382,15 @@ case EVENT_START_ELEMENT: widgetId = getWidgetId(input.attrs); widget = getWidget(widgetId); - gotStylingElement = false; - out.bufferInit(); - return this; - + + if (isVisible(widget)) { + gotStylingElement = false; + out.bufferInit(); + return this; + } else { + // Skip widget and its content + return nullHandler; + } case EVENT_ELEMENT: if (Constants.INSTANCE_NS.equals(input.uri) && STYLING_EL.equals(input.loc)) { gotStylingElement = true; @@ -445,8 +460,12 @@ switch(event) { case EVENT_START_ELEMENT: getRepeaterWidget("RepeaterWidgetHandler"); - out.bufferInit(); - return this; + if (isVisible(widget)) { + out.bufferInit(); + return this; + } else { + return nullHandler; + } case EVENT_ELEMENT: return bufferHandler; case EVENT_END_ELEMENT: @@ -458,7 +477,9 @@ for (int i = 0; i < rowCount; i++) { Repeater.RepeaterRow row = repeater.getRow(i); contextWidget = row; - out.getBuffer().toSAX(EffectWidgetReplacingPipe.this); + if (isVisible(contextWidget)) { + out.getBuffer().toSAX(EffectWidgetReplacingPipe.this); + } } contextWidget = (Widget)contextWidgets.removeFirst(); handler = (Handler)handlers.removeFirst(); @@ -481,9 +502,14 @@ if (!(widget instanceof AggregateField)) { throwWrongWidgetType("AggregateWidgetHandler", input.loc, "aggregate"); } - contextWidgets.addFirst(contextWidget); - contextWidget = widget; - return this; + + if (isVisible(widget)) { + contextWidgets.addFirst(contextWidget); + contextWidget = widget; + return this; + } else { + return nullHandler; + } case EVENT_ELEMENT: return nestedTemplate(); case EVENT_END_ELEMENT: @@ -505,12 +531,16 @@ if (!(widget instanceof Struct)) { throwWrongWidgetType("StructHandler", input.loc, "struct"); } - contextWidgets.addFirst(contextWidget); - contextWidget = widget; - out.element(Constants.INSTANCE_PREFIX, Constants.INSTANCE_NS, "struct"); - out.attributes(); - out.startElement(); - return this; + if (isVisible(widget)) { + contextWidgets.addFirst(contextWidget); + contextWidget = widget; + out.element(Constants.INSTANCE_PREFIX, Constants.INSTANCE_NS, "struct"); + out.attributes(); + out.startElement(); + return this; + } else { + return nullHandler; + } case EVENT_ELEMENT: return nestedTemplate(); case EVENT_END_ELEMENT: @@ -533,11 +563,15 @@ if (!(widget instanceof Union)) { throwWrongWidgetType("UnionHandler", input.loc, "union"); } - contextWidgets.addFirst(contextWidget); - contextWidget = widget; - out.element(Constants.INSTANCE_PREFIX, Constants.INSTANCE_NS, "union"); - out.startElement(); - return this; + if (isVisible(widget)) { + contextWidgets.addFirst(contextWidget); + contextWidget = widget; + out.element(Constants.INSTANCE_PREFIX, Constants.INSTANCE_NS, "union"); + out.startElement(); + return this; + } else { + return nullHandler; + } case EVENT_ELEMENT: if (Constants.TEMPLATE_NS.equals(input.uri)) { if ("case".equals(input.loc)) { Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/dreamteam/flow/team.js ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/dreamteam/flow/team.js (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/dreamteam/flow/team.js Tue Nov 2 02:34:54 2004 @@ -102,7 +102,7 @@ var form = event.source.form; var everyone = form.getAttribute("everyone"); if (everyone != null) { - nameList = everyone.get(value).team; + var nameList = everyone.get(value).team; memberIdwidget.setSelectionList(nameList, "memberId", "name"); // Always set the name value to the first in the list. // Note that it will also fire an event on the @@ -144,7 +144,7 @@ var form = event.source.form; var count = new java.lang.Long(form.getAttribute("counter").longValue() + 1); form.setAttribute("counter", count); - repeater = form.getChild("teammembers"); + var repeater = form.getChild("teammembers"); repeater.getRow(repeater.getSize() - 1).getChild("ID").setValue(count); } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_form.xml ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_form.xml (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_form.xml Tue Nov 2 02:34:54 2004 @@ -32,9 +32,11 @@ if (value != null) { // Get the corresponding type list typewidget.setSelectionList("cocoon:/cars/" + value); + typewidget.setState(Packages.org.apache.cocoon.forms.formmodel.WidgetState.ACTIVE); } else { // Set an empty selection list typewidget.setSelectionList(new Packages.org.apache.cocoon.forms.datatype.EmptySelectionList("Select a maker first")); + typewidget.setState(Packages.org.apache.cocoon.forms.formmodel.WidgetState.DISABLED); } // Always set the type value to null. Note that it will also fire an event on the "type" // widget if it already had a value. @@ -55,7 +57,7 @@ </fd:on-value-changed> </fd:field> - <fd:field id="type" required="true"> + <fd:field id="type" required="true" state="disabled"> <fd:label>Type:</fd:label> <fd:datatype base="string"/> <fd:selection-list> @@ -71,9 +73,11 @@ var makewidget = event.source.lookupWidget("../make"); if (value != null) { modelwidget.setSelectionList("cocoon:/cars/" + makewidget.value + "/" + value); + modelwidget.setState(Packages.org.apache.cocoon.forms.formmodel.WidgetState.ACTIVE); } else { // Set an empty selection list modelwidget.setSelectionList(new Packages.org.apache.cocoon.forms.datatype.EmptySelectionList("Select a type first")); + modelwidget.setState(Packages.org.apache.cocoon.forms.formmodel.WidgetState.INVISIBLE); } // Always set the model value to null. Note that it will also fire an event on the "model" @@ -93,7 +97,7 @@ </fd:on-value-changed> </fd:field> - <fd:field id="model" required="true"> + <fd:field id="model" required="true" state="invisible"> <fd:label>Model:</fd:label> <fd:datatype base="string"/> <fd:selection-list> Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-advanced-field-styling.xsl ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-advanced-field-styling.xsl (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-advanced-field-styling.xsl Tue Nov 2 02:34:54 2004 @@ -123,19 +123,35 @@ <!-- command buttons --> <!-- strangely, IE adds an extra blank line if there only a button on a line. So we surround it with nbsp --> <xsl:text> </xsl:text> - <input type="button" value=">" onclick="opt{generate-id()}.forms_transferRight()"/> + <input type="button" value=">" onclick="opt{generate-id()}.forms_transferRight()"> + <xsl:if test="@state='disabled'"> + <xsl:attribute name="disabled">disabled</xsl:attribute> + </xsl:if> + </input> <xsl:text> </xsl:text> <br/> <xsl:text> </xsl:text> - <input type="button" value=">>" onclick="opt{generate-id()}.forms_transferAllRight()"/> + <input type="button" value=">>" onclick="opt{generate-id()}.forms_transferAllRight()"> + <xsl:if test="@state='disabled'"> + <xsl:attribute name="disabled">disabled</xsl:attribute> + </xsl:if> + </input> <xsl:text> </xsl:text> <br/> <xsl:text> </xsl:text> - <input type="button" value="<" onclick="opt{generate-id()}.forms_transferLeft()"/> + <input type="button" value="<" onclick="opt{generate-id()}.forms_transferLeft()"> + <xsl:if test="@state='disabled'"> + <xsl:attribute name="disabled">disabled</xsl:attribute> + </xsl:if> + </input> <xsl:text> </xsl:text> <br/> <xsl:text> </xsl:text> - <input type="button" value="<<" onclick="opt{generate-id()}.forms_transferAllLeft()"/> + <input type="button" value="<<" onclick="opt{generate-id()}.forms_transferAllLeft()"> + <xsl:if test="@state='disabled'"> + <xsl:attribute name="disabled">disabled</xsl:attribute> + </xsl:if> + </input> <xsl:text> </xsl:text> <br/> <xsl:apply-templates select="." mode="common"/> Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-calendar-styling.xsl ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-calendar-styling.xsl (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-calendar-styling.xsl Tue Nov 2 02:34:54 2004 @@ -69,11 +69,19 @@ </input> <!-- calendar popup --> - <a href="#" name="{$id}" id="{$id}" - onClick="forms_calendar.select(forms_getForm(this)['[EMAIL PROTECTED]'],'{$id}','{$format}'); return false;"> - <!-- TODO: i18n key for @alt --> - <img src="{$resources-uri}/cal.gif" alt="Calendar"/> - </a> + <xsl:choose> + <xsl:when test="@state = 'disabled'"> + <!-- TODO: i18n key for @alt --> + <img src="{$resources-uri}/cal.gif" alt="Calendar"/> + </xsl:when> + <xsl:otherwise> + <a href="#" name="{$id}" id="{$id}" + onclick="forms_calendar.select(forms_getForm(this)['[EMAIL PROTECTED]'],'{$id}','{$format}'); return false;"> + <!-- TODO: i18n key for @alt --> + <img src="{$resources-uri}/cal.gif" alt="Calendar"/> + </a> + </xsl:otherwise> + </xsl:choose> <!-- common stuff --> <xsl:apply-templates select="." mode="common"/> Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl Tue Nov 2 02:34:54 2004 @@ -65,6 +65,10 @@ +--> <xsl:template match="fi:*" mode="styling"> <xsl:apply-templates select="fi:styling/@*" mode="styling"/> + + <xsl:if test="@state = 'disabled'"> + <xsl:attribute name="disabled">disabled</xsl:attribute> + </xsl:if> <!--+ | @listbox-size needs to be handled separately as even if it is not Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/sitemap.xmap ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/sitemap.xmap (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/sitemap.xmap Tue Nov 2 02:34:54 2004 @@ -18,8 +18,12 @@ <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"> <map:components> + <map:generators default="file"> + <map:generator name="form" src="org.apache.cocoon.forms.generation.FormsGenerator"/> + </map:generators> <map:transformers default="xalan"> + <map:transformer name="form" src="org.apache.cocoon.forms.transformation.FormsTemplateTransformer"/> <map:transformer name="i18n" src="org.apache.cocoon.transformation.I18nTransformer"> <catalogues default="other"> <catalogue id="other" name="OtherMessages" location="messages"/> Modified: cocoon/branches/BRANCH_2_1_X/status.xml ============================================================================== --- cocoon/branches/BRANCH_2_1_X/status.xml (original) +++ cocoon/branches/BRANCH_2_1_X/status.xml Tue Nov 2 02:34:54 2004 @@ -199,6 +199,10 @@ <changes> <release version="@version@" date="@date@"> + <action dev="SW" type="add"> + CForms: added widget states. All widgets can now have an "active" (default), "disabled" or "invisible" + state. Updated the stylesheets accordingly to use HTML's disabled inputs. + </action> <action dev="AG" type="fix" fixes-bug="29945" due-to="Christoph Gaffga" due-to-email="[EMAIL PROTECTED]"> BetwixtTransformer: removed deprecation warning with latest betwixt </action>