You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Gabriel Belingueres <be...@gmail.com> on 2008/07/21 22:20:42 UTC
[S2] Conversion validation issue
Hi, I'm using Struts 2.1.2:
I have a validation file like this:
<field name="codigoValidacion">
<!--
<field-validator type="conversion" short-circuit="true">
<message key="invalid.fieldvalue.codigoValidacion" />
</field-validator>
-->
<field-validator type="required" short-circuit="true">
<message>El código de validación es requerido</message>
</field-validator>
<field-validator type="int">
<param name="min">1</param>
<message>El código de validación debe ser un número positivo</message>
</field-validator>
</field>
codigoValidacion is an Integer property of the action.
I also have a messages.properties file like with this line:
invalid.fieldvalue.codigoValidacion=El código de validación debe ser un número
The problem is that when there is a conversion error (for example, the
input parameter is the string "x"), there are two error messages on
the input field, and I only want one message.
The current configuration prints:
o El código de validación debe ser un número (fails conversion)
o El código de validación es requerido (fails required validator)
that is, the conversion error is not "short circuited" and the
validations are executed anyway.
If I uncomment the conversion validator above it prints:
o El código de validación debe ser un número (fails conversion)
o El código de validación debe ser un número (fails conversion validator)
I just want to output only the first error line when a conversion error happens.
Is there any way to configure that I can do just that?
IIUC, the ParameterInterceptor javadocs [1] say that the flag
XWorkConverter.REPORT_CONVERSION_ERRORS can be used to not reporting
parameter conversion errors, but setting it in the struts.xml file
like a constant won't work:
<constant name="report.conversion.errors" value="false"/>
though I feel rather unconfortable to disabling this since it force me
to provide conversion validators everywhere anyway.
Also the online guide [2] says:"By default, the conversion interceptor
is included in struts-default.xml in the default stack. To keep
conversion errors from reporting globally, change the interceptor
stack, and add additional validation rules."
Does this means eliminating the "conversionError" interceptor from the
default stack?
Regards,
Gabriel
[1] http://struts.apache.org/2.1.2/struts2-core/apidocs/com/opensymphony/xwork2/interceptor/ParametersInterceptor.html
[2] http://struts.apache.org/2.1.2/docs/type-conversion.html
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [S2] Conversion validation issue
Posted by Buddmeister <db...@unico.com.au>.
I've had exactly the same problem and ended up doing the same thing you
suggested, over-riding the validate() method and checking for existing field
(data conversion) errors and skipping validation if (field) errors were
found.
--
View this message in context: http://www.nabble.com/-S2--Conversion-validation-issue-tp18576772p22862154.html
Sent from the Struts - User mailing list archive at Nabble.com.
Re: [S2] Conversion validation issue
Posted by Gabriel Belingueres <be...@gmail.com>.
That's my experience too. That's why I wanted to avoid validation
after conversion error on a field.
Is there any interest in adding this functionality? I think that would
be fairly easy to add. If I understood the code correctly, it would be
a matter of extending the DefaultActionValidatorManager.validate()
method to check first if the field is in the conversionError map (in
that case it should skip validation of that field).
2008/7/22 Dave Newton <ne...@yahoo.com>:
> --- On Tue, 7/22/08, Gabriel Belingueres <be...@gmail.com> wrote:
>> But then again, eliminating the "conversionError"
>> interceptor from the stack would prevent conversion
>> errors to appear as fieldErrors in the input form,
>> but this would force to use the conversion validator
>> everywhere a non String object is setted by the
>> ParametersInterceptor to show the error?
>
> In my experience most conversion errors also result in validation errors, at least for simple cases.
>
>> Is there any way to configure S2 so that when a conversion
>> error happens on a field, it does NOT try to validate later
>> that specific field in the Validator interceptor?
>
> Not at the moment, AFAIK.
>
> Dave
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [S2] Conversion validation issue
Posted by Dave Newton <ne...@yahoo.com>.
--- On Tue, 7/22/08, Gabriel Belingueres <be...@gmail.com> wrote:
> But then again, eliminating the "conversionError"
> interceptor from the stack would prevent conversion
> errors to appear as fieldErrors in the input form,
> but this would force to use the conversion validator
> everywhere a non String object is setted by the
> ParametersInterceptor to show the error?
In my experience most conversion errors also result in validation errors, at least for simple cases.
> Is there any way to configure S2 so that when a conversion
> error happens on a field, it does NOT try to validate later
> that specific field in the Validator interceptor?
Not at the moment, AFAIK.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [S2] Conversion validation issue
Posted by Gabriel Belingueres <be...@gmail.com>.
But then again, eliminating the "conversionError" interceptor from the
stack would prevent conversion errors to appear as fieldErrors in the
input form, but this would force to use the conversion validator
everywhere a non String object is setted by the ParametersInterceptor
to show the error?
Is there any way to configure S2 so that when a conversion error
happens on a field, it does NOT try to validate later that specific
field in the Validator interceptor?
2008/7/21 Lukasz Lenart <lu...@googlemail.com>:
>> Does this means eliminating the "conversionError" interceptor from the
>> default stack?
>
> Yes ;-)
>
>
> Regards
> --
> Lukasz
> http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [S2] Conversion validation issue
Posted by Lukasz Lenart <lu...@googlemail.com>.
> Does this means eliminating the "conversionError" interceptor from the
> default stack?
Yes ;-)
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org