Re: Validation problems for fields in iterator

Ute Kaiser <[email protected]> Fri, 10 Oct 2025 12:55:46 +0000
Newsgroups gmane.comp.jakarta.struts.user
Message-ID <trinity-20db55b4-befc-42a1-9f20-d74dc9eecee1-1760100946362@trinity-msg-rest-webde-webde-live-f747bc64b-x6swc>
I think, I found the solution by using the "visitor validator"=2E
Is that the right way?
<!-- Field Validator Syntax -->
    <field name=3D"mother=2Echild">
       <field-validator type=3D"visitor">
          <param name=3D"context">myPath=2EChildClass</param>
          <param name=3D"appendPrefix">true</param>
          <message/> Required even though missing in documentation https:/=
/struts=2Eapache=2Eorg/core-developers/visitor-validator
       </field-validator>
    </field>

And for the conversion error not repopulating the field:
Done with this syntax:
<s:textfield name=3D"mother=2Echild[%{#status=2Eindex}]=2Epocketmoney" val=
ue=3D"%{getFormatted('myDoubleFormat','mother=2Echild[' + #status=2Eindex +=
 ']=2Epocketmoney')}"
(This may be trivial for Struts experts but I am not=2E=2E yet=2E=2E=2E)

Only problem left:
2 field errors when entering 'x' for pocketmoney:
- raised by conversion error=20
- raised by required validator
Why is conversion error not sort of short-circuit to prevent further valid=
ation on that field?
(Most of my double fields are not required, so I want to keep the automati=
c=2E)

I tried to add a conversion validator with short-circuit=3D"true" but this=
 caused two identical field errors for the conversion error=2E
(In fact, two 'almost' identical field errors:
The "automatic" conversion error threw my translated xwork=2Edefault=2Einv=
alid=2Efieldvalue=3DUng=C3=BCltiger Wert im Feld ''{0}''=2E as Ung=C3=BClti=
ger Wert im Feld 'mother=2Echild[0]=2Epocketmoney'=2E
The xml conversion validator should have thrown another error but due to m=
y typo error also used xwork=2Edefault=2Einvalid=2Efieldvalue=3DUng=C3=BClt=
iger Wert im Feld ''{0}''=2E But on its way it lost the apostrophe (in Abst=
ractLocalizedTextProvider) and came out as Ung=C3=BCltiger Wert im Feld mot=
her=2Echild[0]=2Epocketmoney=2E )

I could not find a way to remove a field error from the field error=2E

Since this looks odd to users, I would appreciate any advice how you deal =
with this issue=2E

Best regards
Ute


> Gesendet: Donnerstag, 9=2E Oktober 2025 um 21:44
> Von: utkai@web=2Ede=2EINVALID
> An: user@struts=2Eapache=2Eorg
> Betreff: Validation problems for fields in iterator
>
> Hi, I am looking for the right syntax to write validations for fields in=
 iterator=2E
>=20
> <s:iterator value=3D"mother=2Echild" status=3D"status">
>    <s:textfield name=3D"mother=2Echild[%{#status=2Eindex}]=2Ename"/>
>    <s:textfield name=3D"mother=2Echild[%{#status=2Eindex}]=2Epocketmoney=
" value=3D"%{getFormatted('myDoubleFormat','pocketmoney')}" />
> </s:iterator>
> (value=3D"%{getFormatted('myDoubleFormat','mother=2Echild[%{#status=2Ein=
dex}]=2Epocketmoney')}" caused an OGNL error)
>=20
> I tried several xml field validators (requiredstring, stringlength, requ=
ired, double, conversion) starting with:
> <field name=3D"mother=2Echild[]=2Ename"> or <field name=3D"mother=2Echil=
d=2Ename">
> <field name=3D"mother=2Echild[]=2Epocketmoney">
> but I get fielderrors for field mother=2Echild[]=2Ename (required even a=
ll childs have names)
> The required validators throw errors, the rest does nothing=2E
>=20
> And a conversion error ('x' for pocketmoney) pops up but the field is no=
t populated with the bad value=2E
> (getFormatted worked well in not-iterator-fields, but not here=2E)
> <field-validator type=3D"conversion">
> 			<param name=3D"repopulateField">true</param>
> also does not repopulate=2E
>=20
> Before I start writing all the validations on myself, I would like to kn=
ow if there is a better way=2E
> (migrating from Struts1: <field property=3D"pocketmoney" indexedListProp=
erty=3D"child" depends=3D"mask">; can not believe that there is no equivale=
nt in Struts7)
>=20
> By the way, I am missing @DoubleRangeFieldValidator as @Repeatable (as t=
here is for Integer and Long)=2E
> I went into the wrong direction with the double validator, not understan=
ding:
> "maxInclusive - the maximum inclusive value in FloatValue format specifi=
ed by Java language (if none is specified, it will not be checked)=2E"
> For German locale , we have to write 9=2E999,99=2E No float, just so nor=
mal=2E=2E=2E
> And I did not like it that I had to validate decimal places on my own (s=
ilent rounding, no error when not matching my format)
>=20
> Best regards Ute
>=20
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts=2Eapache=2Eorg
> For additional commands, e-mail: user-help@struts=2Eapache=2Eorg
>=20
>