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/03/31 15:12:18 UTC

Visible form validation missing after upgrade from 2.0.11 to 2.1.6

Hi.

The form validation error messages are missing after I upgraded from 
2.0.11 to 2.1.6, and I can't figure out why.  When I submit an invalid 
form, the form just comes back without the visible error messages.

The form:

@Validation
public class MySupportForm {
     private String supportCategory;

     @RequiredStringValidator(message = "Please select a category")
     @StringLengthFieldValidator(message = "Please select a category", 
trim = true, minLength = "1")
     public final String getSupportCategory() {
         return supportCategory;
     }
     ...
}

struts.xml:
        ...
<action name="ShowMySupport" class="my.app.MySupport">
<result>/my/my_support.jsp</result>
<result name="input">/my/my_support.jsp</result>
<interceptor-ref name="defaultInsecureStack"/>
</action>

<action name="MySupport" class="my.app.MySupport" method="doSend">
<result name="input" type="chain">ShowMySupport</result>
<result name="success" type="redirectAction">MyComplete</result>
<interceptor-ref name="defaultInsecureStack"/>

</action>

<action name="MyComplete" class="my.app.MySupport">
<result>/my/my_support_success.jsp</result>
<interceptor-ref name="defaultInsecureStack"/>
</action>
         ...

The jsp:
...
<s:form action="MySupport" cssClass="settings">
<table>
<s:textfield label="Category " name="form.supportCategory" />
         ...
<input type="submit" value="Send e-mail"/>
</table>
</s:form>

Does anyone know why this happens?  The migration guide [1] doesn't 
mention forms or validations as far as I can see.

Henrik
[1] 
http://cwiki.apache.org/S2WIKI/troubleshooting-guide-migrating-from-struts-20x-to-21x.html



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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

Posted by Henrik Brautaset Aronsen <st...@henrik.synth.no>.
On 31-03-09 17:48, Henrik Brautaset Aronsen wrote:
> On 31-03-09 17:22, Musachy Barroso wrote:
>> yeah you need the assignment. Put a breakpoint in
>> ActionSupport.getFieldErrors() and see if it is getting called.
>
> Thanks for your answer.   I put a checkpoint in there, and 
> getFieldErrors() is definitely called (about five times per field, it 
> seems).

Here's my full template, in case it provides more insight:

text.ftl:
<#include "/${parameters.templateDir}/mytheme/controlheader.ftl" />
<#include "/${parameters.templateDir}/simple/text.ftl" />
<#include "/${parameters.templateDir}/mytheme/controlfooter.ftl" />

controlheader.ftl:
<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && 
fieldErrors[parameters.name]??/>
<tr>
<td>
<#if parameters.label?exists>
<label <#t/>
<#if parameters.id?exists>
           for="${parameters.id?html}" <#t/>
</#if>
<#if hasFieldErrors>
           class="errorLabel"<#t/>
<#else>
           class="label"<#t/>
</#if>
 ><#t/>
         ${parameters.label?html}:
<#include "/${parameters.templateDir}/xhtml/tooltip.ftl" />
</label><#t/>
</#if>
</td>
<td>

controlfooter.ftl:
</td>
<td>TEST1
<#if hasFieldErrors>TEST2
<#list fieldErrors[parameters.name] as error>
<div<#rt/>
<#if parameters.id?exists>
             errorFor="${parameters.id}"<#rt/>
</#if>
           class="errorMessage">
             ${error?html}
</div><#t/>
</#list>
</#if>
</td>
</tr>

Best regards,
Henrik



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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

Posted by Henrik Brautaset Aronsen <st...@henrik.synth.no>.
On 31-03-09 17:22, Musachy Barroso wrote:
> yeah you need the assignment. Put a breakpoint in
> ActionSupport.getFieldErrors() and see if it is getting called.
>    

Thanks for your answer.   I put a checkpoint in there, and 
getFieldErrors() is definitely called (about five times per field, it 
seems).

Henrik


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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

Posted by Musachy Barroso <mu...@gmail.com>.
yeah you need the assignment. Put a breakpoint in
ActionSupport.getFieldErrors() and see if it is getting called.

musachy

On Tue, Mar 31, 2009 at 11:08 AM, Henrik Brautaset Aronsen
<st...@henrik.synth.no> wrote:
> hasFieldErrors



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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

Posted by Henrik Brautaset Aronsen <st...@henrik.synth.no>.
On 31-03-09 16:15, Henrik Brautaset Aronsen wrote:
> On 31-03-09 15:12, Henrik Brautaset Aronsen wrote:
>> The form validation error messages are missing after I upgraded from 
>> 2.0.11 to 2.1.6, and I can't figure out why.  When I submit an 
>> invalid form, the form just comes back without the visible error 
>> messages.
> ...
>> The jsp:
>> ...
>> <s:form action="MySupport" cssClass="settings">
>> <table>
>> <s:textfield label="Category " name="form.supportCategory" />
>>         ...
>> <input type="submit" value="Send e-mail"/>
>> </table>
>> </s:form>
>
> 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?

  .. and some more digging.  We have our own controlfooter.tpl, and the 
fieldErrors should have been rendered there (TEST1 is shown, TEST2 is not):

</td>
<td>TEST1
<#if hasFieldErrors>TEST2
<#list fieldErrors[parameters.name] as error>
<div<#rt/>
<#if parameters.id?exists>
             errorFor="${parameters.id}"<#rt/>
</#if>
           class="errorMessage">
             ${error?html}
</div><#t/>
</#list>
</#if>
</td>
</tr>

hasFieldErrors is never true, even though they should have been (because 
<s:fielderror/> certainly show errors.   I've even inserted the 
hasFieldErrors assignment from the struts2-core jar, but it didn't help:

<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && 
fieldErrors[parameters.name]??/>

Still talking to myself,
Henrik


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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

Posted by Henrik Brautaset Aronsen <st...@henrik.synth.no>.
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


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

Posted by Henrik Brautaset Aronsen <st...@henrik.synth.no>.
On 31-03-09 15:12, Henrik Brautaset Aronsen wrote:
> The form validation error messages are missing after I upgraded from 
> 2.0.11 to 2.1.6, and I can't figure out why.  When I submit an invalid 
> form, the form just comes back without the visible error messages.
...
> The jsp:
> ...
> <s:form action="MySupport" cssClass="settings">
> <table>
> <s:textfield label="Category " name="form.supportCategory" />
>         ...
> <input type="submit" value="Send e-mail"/>
> </table>
> </s:form>

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?

Henrik

[1] Or <s:fielderror><s:param value="%{'supportCategory'}" 
/></s:fielderror> for a specific error


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org