Hi Prasanth,

The fieldName attribute on a fieldError tag is not evaluated. You may need to 
move the amount[] string literal inside the OGNL expression, like so: 
%{'amount['+#loop.index+']'}.

You also may need to use #attr.loop.index instead of #loop.index. I've found 
that I've had to use that myself in some situations when using string literals 
in an OGNL expression. 

Please let us know if this fixes it.

Regards,

Nate

-----Original Message-----
From: Prasanth <dbad...@pangburngroup.com> 
Sent: Tuesday, 30 July 2024 17:29
To: Struts Users Mailing List <user@struts.apache.org>
Subject: Displaying errors by the field for array objects

Hi,

I have text fields with names as amount[0], amount[1] etc which are loaded in a 
map in the action class. Trying to display error messages next to each field 
rather than showing all at the top using the code below but it is not working. 
If I just use fielderror tag then I can display all errors at the top of the 
jsp, but would like to display the error messages next to each field.  What is 
the right way to accomplish this?

When adding field errors adding the error as below.
addFieldError("amount["+ rowNumber + "]", getText("error.enter.amount"));

Then trying to display the error in the jsp using the below tag. loop is the 
status var for s:iterator.
<s:fielderror  fieldName="amount[%{#loop.index}]"/>

Below tag is displaying all field errors as if I am using <s:fielderror/> 
<s:fielderror > <param value="amount[%{#loop.index}]"/> </s:fielderror>

Thanks,
Prasanth

Reply via email to