I think, I found the solution by using the "visitor validator".
Is that the right way?
<!-- Field Validator Syntax -->
    <field name="mother.child">
       <field-validator type="visitor">
          <param name="context">myPath.ChildClass</param>
          <param name="appendPrefix">true</param>
          <message/> Required even though missing in documentation 
https://struts.apache.org/core-developers/visitor-validator
       </field-validator>
    </field>

And for the conversion error not repopulating the field:
Done with this syntax:
<s:textfield name="mother.child[%{#status.index}].pocketmoney" 
value="%{getFormatted('myDoubleFormat','mother.child[' + #status.index + 
'].pocketmoney')}"
(This may be trivial for Struts experts but I am not.. yet...)

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

I tried to add a conversion validator with short-circuit="true" but this caused 
two identical field errors for the conversion error.
(In fact, two 'almost' identical field errors:
The "automatic" conversion error threw my translated 
xwork.default.invalid.fieldvalue=Ungültiger Wert im Feld ''{0}''. as Ungültiger 
Wert im Feld 'mother.child[0].pocketmoney'.
The xml conversion validator should have thrown another error but due to my 
typo error also used xwork.default.invalid.fieldvalue=Ungültiger Wert im Feld 
''{0}''. But on its way it lost the apostrophe (in 
AbstractLocalizedTextProvider) and came out as Ungültiger Wert im Feld 
mother.child[0].pocketmoney. )

I could not find a way to remove a field error from the field error.

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

Best regards
Ute


> Gesendet: Donnerstag, 9. Oktober 2025 um 21:44
> Von: [email protected]
> An: [email protected]
> Betreff: Validation problems for fields in iterator
>
> Hi, I am looking for the right syntax to write validations for fields in 
> iterator.
> 
> <s:iterator value="mother.child" status="status">
>    <s:textfield name="mother.child[%{#status.index}].name"/>
>    <s:textfield name="mother.child[%{#status.index}].pocketmoney" 
> value="%{getFormatted('myDoubleFormat','pocketmoney')}" />
> </s:iterator>
> (value="%{getFormatted('myDoubleFormat','mother.child[%{#status.index}].pocketmoney')}"
>  caused an OGNL error)
> 
> I tried several xml field validators (requiredstring, stringlength, required, 
> double, conversion) starting with:
> <field name="mother.child[].name"> or <field name="mother.child.name">
> <field name="mother.child[].pocketmoney">
> but I get fielderrors for field mother.child[].name (required even all childs 
> have names)
> The required validators throw errors, the rest does nothing.
> 
> And a conversion error ('x' for pocketmoney) pops up but the field is not 
> populated with the bad value.
> (getFormatted worked well in not-iterator-fields, but not here.)
> <field-validator type="conversion">
>                       <param name="repopulateField">true</param>
> also does not repopulate.
> 
> Before I start writing all the validations on myself, I would like to know if 
> there is a better way.
> (migrating from Struts1: <field property="pocketmoney" 
> indexedListProperty="child" depends="mask">; can not believe that there is no 
> equivalent in Struts7)
> 
> By the way, I am missing @DoubleRangeFieldValidator as @Repeatable (as there 
> is for Integer and Long).
> I went into the wrong direction with the double validator, not understanding:
> "maxInclusive - the maximum inclusive value in FloatValue format specified by 
> Java language (if none is specified, it will not be checked)."
> For German locale , we have to write 9.999,99. No float, just so normal...
> And I did not like it that I had to validate decimal places on my own (silent 
> rounding, no error when not matching my format)
> 
> Best regards Ute
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to