You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by br...@apache.org on 2005/10/21 11:15:44 UTC
svn commit: r327137 - in
/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms:
formmodel/MultiValueField.java system/i18n/messages.xml
system/i18n/messages_fr.xml system/i18n/messages_nl.xml
Author: bruno
Date: Fri Oct 21 02:15:37 2005
New Revision: 327137
URL: http://svn.apache.org/viewcvs?rev=327137&view=rev
Log:
Some further changes related to the removal of the selection-list-required restriction for multivaluefields:
* in generateItemSaxFragment, the convertor was called on the enteredValues, which does not make sense since those are always strings
* in the validation error message, show the value on which the validation failed (translations need updating)
* always use the normal convertor. I don't know plain convertor was used by default, maybe in earlier times selection lists encoded their value always as plain? Anyway, I don't see how this could ever have worked for valuetypes where the plain convertor isn't the default (or very similar).
Modified:
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages.xml
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages_fr.xml
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages_nl.xml
Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java?rev=327137&r1=327136&r2=327137&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java Fri Oct 21 02:15:37 2005
@@ -62,6 +62,7 @@
private SelectionList selectionList;
private String[] enteredValues;
+ private String invalidEnteredValue;
private Object[] values;
private ValidationError validationError;
@@ -84,16 +85,12 @@
return;
enteredValues = formContext.getRequest().getParameterValues(getRequestParameterName());
+ invalidEnteredValue = null;
validationError = null;
values = null;
boolean conversionFailed = false;
if (enteredValues != null) {
- // Normally, for MultiValueFields, the user selects the values from
- // a SelectionList, and the values in a SelectionList are garanteed to
- // be valid, so the conversion from String to native datatype should
- // never fail. But it could fail if users start messing around with
- // request parameters.
Object[] tempValues = (Object[])Array.newInstance(getDatatype().getTypeClass(), enteredValues.length);
for (int i = 0; i < enteredValues.length; i++) {
String param = enteredValues[i];
@@ -102,6 +99,7 @@
tempValues[i] = conversionResult.getResult();
} else {
conversionFailed = true;
+ invalidEnteredValue = param;
break;
}
}
@@ -124,7 +122,7 @@
if (values != null) {
validationError = definition.getDatatype().validate(values, new ExpressionContextImpl(this));
} else {
- validationError = new ValidationError(new I18nMessage("multivaluefield.conversionfailed", FormsConstants.I18N_CATALOGUE));
+ validationError = new ValidationError(new I18nMessage("multivaluefield.conversionfailed", new String[] {invalidEnteredValue}, FormsConstants.I18N_CATALOGUE));
}
this.wasValid = validationError == null ? super.validate() : false;
@@ -140,10 +138,7 @@
public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
contentHandler.startElement(FormsConstants.INSTANCE_NS, VALUES_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALUES_EL, XMLUtils.EMPTY_ATTRIBUTES);
- Convertor convertor = definition.getDatatype().getPlainConvertor();
- if (convertor == null) {
- convertor = definition.getDatatype().getConvertor();
- }
+ Convertor convertor = definition.getDatatype().getConvertor();
if (values != null) {
for (int i = 0; i < values.length; i++) {
contentHandler.startElement(FormsConstants.INSTANCE_NS, VALUE_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALUE_EL, XMLUtils.EMPTY_ATTRIBUTES);
@@ -154,7 +149,7 @@
} else if (enteredValues != null) {
for (int i = 0; i < enteredValues.length; i++) {
contentHandler.startElement(FormsConstants.INSTANCE_NS, VALUE_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALUE_EL, XMLUtils.EMPTY_ATTRIBUTES);
- String value = convertor.convertToString(enteredValues[i], locale, null);
+ String value = enteredValues[i];
contentHandler.characters(value.toCharArray(), 0, value.length());
contentHandler.endElement(FormsConstants.INSTANCE_NS, VALUE_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALUE_EL);
}
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=327137&r1=327136&r2=327137&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 Fri Oct 21 02:15:37 2005
@@ -42,8 +42,7 @@
most {1} items should be selected.</message>
<message key="validation.array.min-valuecount">At least {0} item(s) should be selected.</message>
<message key="validation.array.max-valuecount">At most {0} items should be selected.</message>
- <message key="multivaluefield.conversionfailed">One of the selected values is
- of an incorrect type.</message>
+ <message key="multivaluefield.conversionfailed">This value is not valid: {0}</message>
<message key="validation.numeric.range">Number should be in the range from
{0} to {1}.</message>
<message key="validation.numeric.min">Number should be greater than or equal
Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages_fr.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages_fr.xml?rev=327137&r1=327136&r2=327137&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages_fr.xml (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages_fr.xml Fri Oct 21 02:15:37 2005
@@ -43,7 +43,7 @@
<message key="validation.array.min-valuecount">Au moins {0} éléments doivent être séléctionnés.</message>
<message key="validation.array.max-valuecount">Au plus {0} éléments peuvent être séléctionnés.</message>
- <message key="multivaluefield.conversionfailed">Un des éléments séléctionnées a un type incorrect.</message>
+ <message key="multivaluefield.conversionfailed">Cette donnée n'est pas correct: {0}</message>
<message key="validation.numeric.range">Doit être compris entre {0} et {1}.</message>
<message key="validation.numeric.min">Doit être supérieur ou égal à {0}.</message>
Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages_nl.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages_nl.xml?rev=327137&r1=327136&r2=327137&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages_nl.xml (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/system/i18n/messages_nl.xml Fri Oct 21 02:15:37 2005
@@ -43,7 +43,7 @@
<message key="validation.array.range-valuecount">Kies tussen de {0} en {1} elementen.</message>
<message key="validation.array.min-valuecount">Kies minimaal {0} elementen.</message>
<message key="validation.array.max-valuecount">Kies maximaal {0} elementen.</message>
- <message key="multivaluefield.conversionfailed">Een van de gekozen waarden is ongeldig.</message>
+ <message key="multivaluefield.conversionfailed">Deze waarde is ongeldig: {0}</message>
<message key="validation.numeric.range">De waarde moet liggen tussen {0} en {1}.</message>
<message key="validation.numeric.min">De waarde is minimaal {0}.</message>
<message key="validation.numeric.max">De waarde is maximaal {0}.</message>