You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jh...@apache.org on 2005/10/06 10:28:09 UTC
svn commit: r306551 - in
/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms: formmodel/
generation/ resources/ system/i18n/ transformation/
Author: jheymans
Date: Thu Oct 6 01:27:55 2005
New Revision: 306551
URL: http://svn.apache.org/viewcvs?rev=306551&view=rev
Log:
<action dev="JHS" type="add" due-to="Thomas Lutz" due-to-email="mattom@gmx.at">
CForms: The repeater widget now supports min and max-size attributes and sets a validation error when these boundaries are crossed.
</action>
Modified:
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/RepeaterDefinition.java
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/RepeaterDefinitionBuilder.java
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/template.jx
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/resources/forms-field-styling.xsl
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages.xml
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java
Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java?rev=306551&r1=306550&r2=306551&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java Thu Oct 6 01:27:55 2005
@@ -22,6 +22,7 @@
import org.apache.cocoon.forms.Constants;
import org.apache.cocoon.forms.FormContext;
+import org.apache.cocoon.forms.util.I18nMessage;
import org.apache.cocoon.forms.event.WidgetEvent;
import org.apache.cocoon.forms.validation.ValidationError;
import org.apache.cocoon.forms.validation.ValidationErrorAware;
@@ -51,6 +52,7 @@
private static final String HEADING_EL = "heading";
private static final String LABEL_EL = "label";
private static final String REPEATER_SIZE_EL = "repeater-size";
+ private static final String REPEATER_VALIDATION_MESSAGE_EL = "repeater-validation-message";
private final RepeaterDefinition definition;
private final List rows = new ArrayList();
@@ -82,6 +84,14 @@
return rows.size();
}
+ public int getMinimumSize() {
+ return this.definition.getMinimumSize();
+ }
+
+ public int getMaximumSize() {
+ return this.definition.getMaximumSize();
+ }
+
public RepeaterRow addRow() {
RepeaterRow repeaterRow = new RepeaterRow(definition);
rows.add(repeaterRow);
@@ -275,6 +285,15 @@
valid = valid & row.validate();
}
+ if (rows.size() > getMaximumSize() || rows.size() < getMinimumSize()) {
+ String [] boundaries = new String[2];
+ boundaries[0] = String.valueOf(getMinimumSize());
+ boundaries[1] = String.valueOf(getMaximumSize());
+ this.validationError = new ValidationError(new I18nMessage("repeater.cardinality", boundaries, Constants.I18N_CATALOGUE));
+ valid=false;
+ }
+
+
if (valid) {
valid = super.validate();
}
@@ -300,6 +319,8 @@
public AttributesImpl getXMLElementAttributes() {
AttributesImpl attrs = super.getXMLElementAttributes();
attrs.addCDATAAttribute("size", String.valueOf(getSize()));
+ attrs.addCDATAAttribute("minimum-size", String.valueOf(getMinimumSize()));
+ attrs.addCDATAAttribute("maximum-size", String.valueOf(getMaximumSize()));
return attrs;
}
@@ -351,6 +372,14 @@
AttributesImpl attrs = getXMLElementAttributes();
contentHandler.startElement(Constants.INSTANCE_NS, REPEATER_SIZE_EL, Constants.INSTANCE_PREFIX_COLON + REPEATER_SIZE_EL, attrs);
contentHandler.endElement(Constants.INSTANCE_NS, REPEATER_SIZE_EL, Constants.INSTANCE_PREFIX_COLON + REPEATER_SIZE_EL);
+ }
+
+ public void generateValidationMessage(ContentHandler contentHandler) throws SAXException {
+ if (validationError != null ) {
+ contentHandler.startElement(Constants.INSTANCE_NS, REPEATER_VALIDATION_MESSAGE_EL, Constants.INSTANCE_PREFIX_COLON + REPEATER_VALIDATION_MESSAGE_EL, XMLUtils.EMPTY_ATTRIBUTES);
+ this.validationError.generateSaxFragment(contentHandler);
+ contentHandler.endElement(Constants.INSTANCE_NS, REPEATER_VALIDATION_MESSAGE_EL, Constants.INSTANCE_PREFIX_COLON + REPEATER_VALIDATION_MESSAGE_EL);
+ }
}
/**
Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/RepeaterDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/RepeaterDefinition.java?rev=306551&r1=306550&r2=306551&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/RepeaterDefinition.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/RepeaterDefinition.java Thu Oct 6 01:27:55 2005
@@ -22,25 +22,30 @@
*/
public class RepeaterDefinition extends AbstractContainerDefinition {
private int initialSize = 0;
+ private int minimumSize;
+ private int maximumSize;
- public RepeaterDefinition(int initialSize) {
+ public RepeaterDefinition(int initialSize, int minSize, int maxSize) {
super();
this.initialSize = initialSize;
+ this.minimumSize = minSize;
+ this.maximumSize = maxSize;
}
/**
* initialize this definition with the other, sort of like a copy constructor
*/
public void initializeFrom(WidgetDefinition definition) throws Exception {
- super.initializeFrom(definition);
-
- if(definition instanceof RepeaterDefinition) {
- RepeaterDefinition other = (RepeaterDefinition)definition;
-
- this.initialSize = other.initialSize;
- } else {
- throw new Exception("Definition to inherit from is not of the right type! (at "+getLocation()+")");
- }
+ super.initializeFrom(definition);
+
+ if(definition instanceof RepeaterDefinition) {
+ RepeaterDefinition other = (RepeaterDefinition)definition;
+ this.initialSize = other.initialSize;
+ this.maximumSize = other.maximumSize;
+ this.minimumSize = other.minimumSize;
+ } else {
+ throw new Exception("Definition to inherit from is not of the right type! (at "+getLocation()+")");
+ }
}
public Widget createInstance() {
@@ -49,5 +54,13 @@
public int getInitialSize() {
return this.initialSize;
+ }
+
+ public int getMaximumSize() {
+ return this.maximumSize;
+ }
+
+ public int getMinimumSize() {
+ return this.minimumSize;
}
}
Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/RepeaterDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/RepeaterDefinitionBuilder.java?rev=306551&r1=306550&r2=306551&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/RepeaterDefinitionBuilder.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/RepeaterDefinitionBuilder.java Thu Oct 6 01:27:55 2005
@@ -28,8 +28,20 @@
public WidgetDefinition buildWidgetDefinition(Element repeaterElement) throws Exception {
int initialSize = DomHelper.getAttributeAsInteger(repeaterElement, "initial-size", 0);
-
- RepeaterDefinition repeaterDefinition = new RepeaterDefinition(initialSize);
+ int minimumSize = DomHelper.getAttributeAsInteger(repeaterElement, "minimum-size", 0);
+ int maximumSize = DomHelper.getAttributeAsInteger(repeaterElement, "maximum-size", Integer.MAX_VALUE);
+
+ // should throw error on negative values ? Just correct them for now.
+ if (minimumSize < 0)
+ minimumSize = 0;
+
+ if (maximumSize < 0)
+ maximumSize = Integer.MAX_VALUE;
+
+ // initialsize is at least the minimumsize
+ initialSize = minimumSize > initialSize ? minimumSize : initialSize;
+
+ RepeaterDefinition repeaterDefinition = new RepeaterDefinition(initialSize, minimumSize, maximumSize);
super.setupDefinition(repeaterElement, repeaterDefinition);
setDisplayData(repeaterElement, repeaterDefinition);
Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java?rev=306551&r1=306550&r2=306551&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java Thu Oct 6 01:27:55 2005
@@ -309,6 +309,10 @@
private static final String VALIDATION_ERROR = "validation-error";
+ public void generateRepeaterValidationMessage(Widget widget, String id) throws SAXException {
+ getRepeater(widget, id).generateValidationMessage(this.cocoonConsumer);
+ }
+
public void generateValidationError(ValidationError error) throws SAXException {
// Needs to be buffered
RootBufferingPipe pipe = new RootBufferingPipe(this.cocoonConsumer);
Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml?rev=306551&r1=306550&r2=306551&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml Thu Oct 6 01:27:55 2005
@@ -77,7 +77,16 @@
<jx:set var="cformsDummy" value="${cformsHelper.generateRepeaterSize(widget, id)}"/>
</jx:macro>
-
+
+ <!--
+ ft:repeater-validation-error
+ -->
+ <jx:macro name="repeater-validation-message" targetNamespace="http://apache.org/cocoon/forms/1.0#template">
+ <jx:parameter name="id"/>
+
+ <jx:set var="cformsDummy" value="${cformsHelper.generateRepeaterValidationMessage(widget, id)}"/>
+ </jx:macro>
+
<!--
ft:repeater-widget
-->
Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/template.jx
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/template.jx?rev=306551&r1=306550&r2=306551&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/template.jx (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/template.jx Thu Oct 6 01:27:55 2005
@@ -57,6 +57,11 @@
${context_widget_.lookupWidget(id).unwrap().generateSize(cocoon.consumer)}
</jx:macro>
+<jx:macro name="repeater-validation-message" targetNamespace="http://apache.org/cocoon/forms/1.0#template">
+<jx:parameter name="id"/>
+${context_widget_.lookupWidget(id).unwrap().generateValidationMessage(cocoon.consumer)}
+</jx:macro>
+
<jx:macro name="repeater-widget" targetNamespace="http://apache.org/cocoon/forms/1.0#template" xmlns:ft="http://apache.org/cocoon/forms/1.0#template">
<jx:parameter name="id"/>
<jx:set var="repeater_" value="${context_widget_.lookupWidget(id)}"/>
Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/resources/forms-field-styling.xsl
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/resources/forms-field-styling.xsl?rev=306551&r1=306550&r2=306551&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/resources/forms-field-styling.xsl (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/resources/forms-field-styling.xsl Thu Oct 6 01:27:55 2005
@@ -161,7 +161,7 @@
<!--+
|
+-->
- <xsl:template match="fi:validation-message">
+ <xsl:template match="fi:validation-message|fi:repeater-validation-message">
<a href="#" class="forms-validation-message">
<xsl:attribute name="onclick">
<xsl:text>alert('</xsl:text>
Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages.xml?rev=306551&r1=306550&r2=306551&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages.xml (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages.xml Thu Oct 6 01:27:55 2005
@@ -55,4 +55,5 @@
<message key="upload.invalid-type">Invalid content type: {0}.</message>
<message key="upload.rejected">Upload size too large ({0} kbytes). Only {1} kbytes are allowed.</message>
<message key="calendar.alt">Calendar</message>
+ <message key="repeater.cardinality">This repeater must contain {0} to {1} rows.</message>
</catalogue>
Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java?rev=306551&r1=306550&r2=306551&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java Thu Oct 6 01:27:55 2005
@@ -79,6 +79,7 @@
private static final String GROUP = "group";
private static final String NEW = "new";
private static final String REPEATER_SIZE = "repeater-size";
+ private static final String REPEATER_VALIDATION_MESSAGE = "repeater-validation-message";
private static final String REPEATER_WIDGET = "repeater-widget";
private static final String REPEATER_WIDGET_LABEL = "repeater-widget-label";
private static final String STRUCT = "struct";
@@ -88,27 +89,28 @@
private static final String WIDGET = "widget";
private static final String WIDGET_LABEL = "widget-label";
- private final AggregateWidgetHandler hAggregate = new AggregateWidgetHandler();
- private final ChooseHandler hChoose = new ChooseHandler();
- private final ChoosePassThruHandler hChoosePassThru = new ChoosePassThruHandler();
- private final ClassHandler hClass = new ClassHandler();
- private final ContinuationIdHandler hContinuationId = new ContinuationIdHandler();
- private final DocHandler hDocument = new DocHandler();
- private final FormHandler hForm = new FormHandler();
- private final GroupHandler hGroup = new GroupHandler();
- private final NestedHandler hNested = new NestedHandler();
- private final NewHandler hNew = new NewHandler();
- private final RepeaterSizeHandler hRepeaterSize = new RepeaterSizeHandler();
- private final RepeaterWidgetHandler hRepeaterWidget = new RepeaterWidgetHandler();
- private final RepeaterWidgetLabelHandler hRepeaterWidgetLabel = new RepeaterWidgetLabelHandler();
- private final SkipHandler hSkip = new SkipHandler();
- private final StructHandler hStruct = new StructHandler();
- private final StylingContentHandler hStyling = new StylingContentHandler();
- private final UnionHandler hUnion = new UnionHandler();
- private final UnionPassThruHandler hUnionPassThru = new UnionPassThruHandler();
- private final ValidationErrorHandler hValidationError = new ValidationErrorHandler();
- private final WidgetHandler hWidget = new WidgetHandler();
- private final WidgetLabelHandler hWidgetLabel = new WidgetLabelHandler();
+ private final AggregateWidgetHandler hAggregate = new AggregateWidgetHandler();
+ private final ChooseHandler hChoose = new ChooseHandler();
+ private final ChoosePassThruHandler hChoosePassThru = new ChoosePassThruHandler();
+ private final ClassHandler hClass = new ClassHandler();
+ private final ContinuationIdHandler hContinuationId = new ContinuationIdHandler();
+ private final DocHandler hDocument = new DocHandler();
+ private final FormHandler hForm = new FormHandler();
+ private final GroupHandler hGroup = new GroupHandler();
+ private final NestedHandler hNested = new NestedHandler();
+ private final NewHandler hNew = new NewHandler();
+ private final RepeaterSizeHandler hRepeaterSize = new RepeaterSizeHandler();
+ private final RepeaterValidationMessageHandler hRepeaterValidationMessage = new RepeaterValidationMessageHandler();
+ private final RepeaterWidgetHandler hRepeaterWidget = new RepeaterWidgetHandler();
+ private final RepeaterWidgetLabelHandler hRepeaterWidgetLabel = new RepeaterWidgetLabelHandler();
+ private final SkipHandler hSkip = new SkipHandler();
+ private final StructHandler hStruct = new StructHandler();
+ private final StylingContentHandler hStyling = new StylingContentHandler();
+ private final UnionHandler hUnion = new UnionHandler();
+ private final UnionPassThruHandler hUnionPassThru = new UnionPassThruHandler();
+ private final ValidationErrorHandler hValidationError = new ValidationErrorHandler();
+ private final WidgetHandler hWidget = new WidgetHandler();
+ private final WidgetLabelHandler hWidgetLabel = new WidgetLabelHandler();
/**
* Map containing all handlers
@@ -535,6 +537,23 @@
throws SAXException {
setTypedWidget(loc, attrs, Repeater.class, "repeater");
((Repeater) widget).generateSize(getContentHandler());
+ widget = null;
+ return this;
+ }
+
+ public void endElement(String uri, String loc, String raw)
+ throws SAXException {
+ }
+ }
+
+ /**
+ * Handles <code>ft:repeater-validation-message</code> element.
+ */
+ protected class RepeaterValidationMessageHandler extends ErrorHandler {
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ setTypedWidget(loc, attrs, Repeater.class, "repeater");
+ ((Repeater) widget).generateValidationMessage(getContentHandler());
widget = null;
return this;
}
Re: svn commit: r306551 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms:
formmodel/ generation/ resources/ system/i18n/ transformation/
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Sylvain Wallez wrote:
> I would like to avoid instruction proliferation in the template
> language. We already have <ft:validation-error> that does the exact same
> job.
>
> Any objection for me to remove <ft:repeater-validation-message> (I'm
> ready to commit!)?
+1!
Vadim
Re: svn commit: r306551 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms:
formmodel/ generation/ resources/ system/i18n/ transformation/
Posted by Jorg Heymans <jh...@domek.be>.
Sylvain Wallez wrote:
>
> I would like to avoid instruction proliferation in the template
> language. We already have <ft:validation-error> that does the exact same
> job.
>
> Any objection for me to remove <ft:repeater-validation-message> (I'm
> ready to commit!)?
>
yup I missed that one sorry.
+1
Jorg
Re: svn commit: r306551 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms:
formmodel/ generation/ resources/ system/i18n/ transformation/
Posted by Reinhard Poetz <re...@apache.org>.
Sylvain Wallez wrote:
> I would like to avoid instruction proliferation in the template
> language. We already have <ft:validation-error> that does the exact same
> job.
>
> Any objection for me to remove <ft:repeater-validation-message> (I'm
> ready to commit!)?
yes, please
--
Reinhard Pötz Independent Consultant, Trainer & (IT)-Coach
{Software Engineering, Open Source, Web Applications, Apache Cocoon}
web(log): http://www.poetz.cc
--------------------------------------------------------------------
___________________________________________________________
Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de
Re: svn commit: r306551 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms:
formmodel/ generation/ resources/ system/i18n/ transformation/
Posted by Sylvain Wallez <sy...@anyware-tech.com>.
jheymans@apache.org wrote:
>Author: jheymans
>Date: Thu Oct 6 01:27:55 2005
>New Revision: 306551
>
>URL: http://svn.apache.org/viewcvs?rev=306551&view=rev
>
>
>--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java (original)
>+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java Thu Oct 6 01:27:55 2005
>
>
>+ public void generateValidationMessage(ContentHandler contentHandler) throws SAXException {
>+ if (validationError != null ) {
>+ contentHandler.startElement(Constants.INSTANCE_NS, REPEATER_VALIDATION_MESSAGE_EL, Constants.INSTANCE_PREFIX_COLON + REPEATER_VALIDATION_MESSAGE_EL, XMLUtils.EMPTY_ATTRIBUTES);
>+ this.validationError.generateSaxFragment(contentHandler);
>+ contentHandler.endElement(Constants.INSTANCE_NS, REPEATER_VALIDATION_MESSAGE_EL, Constants.INSTANCE_PREFIX_COLON + REPEATER_VALIDATION_MESSAGE_EL);
>+ }
> }
>
>
>--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml (original)
>+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml Thu Oct 6 01:27:55 2005
>@@ -77,7 +77,16 @@
>
>
>+
>+ <!--
>+ ft:repeater-validation-error
>+ -->
>+ <jx:macro name="repeater-validation-message" targetNamespace="http://apache.org/cocoon/forms/1.0#template">
>+ <jx:parameter name="id"/>
>+
>+ <jx:set var="cformsDummy" value="${cformsHelper.generateRepeaterValidationMessage(widget, id)}"/>
>+ </jx:macro>
>+
>
>
I would like to avoid instruction proliferation in the template
language. We already have <ft:validation-error> that does the exact same
job.
Any objection for me to remove <ft:repeater-validation-message> (I'm
ready to commit!)?
Sylvain
--
Sylvain Wallez Anyware Technologies
http://people.apache.org/~sylvain http://www.anyware-tech.com
Apache Software Foundation Member Research & Technology Director