struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gabriel Belingueres" <belingue...@gmail.com>
Subject [S2] Conversion validation issue
Date Mon, 21 Jul 2008 20:20:42 GMT
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


Mime
View raw message