struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gabriel Belingueres" <>
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 type="required" short-circuit="true">
      <message>El código de validación es requerido</message>
		<field-validator type="int">
			<param name="min">1</param>
			<message>El código de validación debe ser un número positivo</message>

codigoValidacion is an Integer property of the action.

I also have a 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?



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message