File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes struts 2 - client side basic validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts 2 - client side basic validation" Watch "struts 2 - client side basic validation" New topic
Author

struts 2 - client side basic validation

Peter Molina
Greenhorn

Joined: Mar 04, 2010
Posts: 1
Hello,

I am playin with struts 2.1.8 + tiles and trying out client side validation and running in a strange issue with required string validation, regardless of whether or not a value is put in the text field, after clicking submit, struts always display the error message from action-validation.xml and the text field value clears out. When value is put in the text field, I would expect submit to take it the execute() of dosubmit class. For actions without validation everything works as expected. I think I am missing something very basic. Code snippets -

struts.xml -

<action name="dosubmit" class="com.group.dosubmit">
<result name="success" type="tiles">successpageDef</result>
<result name="input" type="tiles">inputpageDef</result>
</action>

inputpageDef body -

s:form action="dosubmit" method="post" validate="true" >
<div>
<s:textfield name="first" key="first" label="First" size="15" />
<s:submit value="Submit"/>
</div>
</s:form>

dosubmit-validation.xml -

<validators>
<field name="first">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>First is required</message>
</field-validator>
</field>
</validators>

Any help/pointers is appreciated.

thanks,
Peter
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read.

You can edit your post by using the button.

By the way, if you use the "key" attribute, there's little reason to use the "name" and "label" attributes; the "key" attribute is meant to eliminate the need for them.

I don't see anything obviously wrong; did you check to make sure the correct JavaScript is rendering? I'd also remove the <div> tags around the for elements; I'm not sure if that's legal HTML (wrapping div tags around table rows, I mean)--not sure, and can't check at the moment.

Welcome to JavaRanch!
 
wood burning stoves
 
subject: struts 2 - client side basic validation
 
Similar Threads
problems validation.xml in struts 2
problems in validation part of struts 2
Struts2 & validation [SOLVED]
Struts 2 Validation
Struts2: Cannot submit action after a second validation attempt.