You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Henrik Brautaset Aronsen <st...@henrik.synth.no> on 2009/04/01 09:06:15 UTC

Re: Visible form validation missing after upgrade from 2.0.11 to 2.1.6

On 31-03-09 16:15, Henrik Brautaset Aronsen wrote:
> I've done some more digging:  I can see the error messages by using 
> <s:fielderror/> [1], but why aren't they automatically attached to the 
> <s:textfield> like they were in Struts 2.0.x?

I managed to solve my problem.  I believe it's a bug, and I've created 
it as WW-3069 [1].   Here's the bug report:


After upgrading from Struts 2.0.11 to 2.1.6, fieldErrors weren't 
displayed next to form fields any more. The validation still worked, 
because I could still see the errors by issuing a <s:fielderror/>.

My form is a value on the action, and is addressed like this:
<s:textfield label="Your e-mail address" name="form.email" 
theme="mytheme" />

I noticed that to access a separate value in fieldError in 2.1.6, I had 
to chop off "form.":
<s:fielderror fieldName="form.email" /> <!-- doesn't show anything -->
<s:fielderror fieldName="email" /> <!-- shows the error-->

Now, to be able to show my error using my template, I had to add an ID 
to my textfield:
<s:textfield label="Your e-mail address" id="email" name="form.email" 
theme="mytheme" />

Then I had to change the default hasErrorField assignment in the 
controlheader.tpl template:
<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && 
fieldErrors[parameters.name]??/> <!-- does not work -->
<#assign hasFieldErrors = parameters.id?? && fieldErrors?? && 
fieldErrors[parameters.id]??/> <!-- works as intended -->

And change way I fetched errors in my controlfooter.tpl:
<#list fieldErrors[parameters.name] as error> <!-- does not work -->
<#list fieldErrors[parameters.id] as error> <!-- works -->

Voila! I can see field errors again.

Just to summarize: To access a fieldError, I have to manually strip 
"form."from "form.email". I also have to set an additional ID on my form 
fields (with the stripped value) to be able to access it from my 
template. Is this the intended behaviour?


Best regards,
Henrik

[1] https://issues.apache.org/struts/browse/WW-3069