Hi Nate,
Tried it with and without attr but that didn't work. After trying various
things below code worked. Using OGNL to set value attribute of s:param didn't
work either.
<c:set var="amountIndex" value="amount[${loop.index}]"/>
<s:fielderror> <s:param>${amountIndex}</s:param> </s:fielderror>
Following did not work:
1. <s:fielderror fieldName="%{amountIndex}"/>
2. <s:fielderror fieldName="%{'amount[' + #attr.loop.index + ']'}"/>
3. <s:fielderror> <s:param value="%{amountIndex}"/> </s:fielderror>
Thanks,
Prasanth
On 7/31/24 6:28 AM, Nate Kerkhofs wrote:
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
---------------------------------------------------------------------
To unsubscribe, e-mail:user-unsubscr...@struts.apache.org
For additional commands, e-mail:user-h...@struts.apache.org