Java Mailing List Archive

http://www.gg3721.com/

Home » Struts Users Mailing List »

AJAX Validation (calls to action methods work on submit, but messages
not displayed nor page redirected)

Alex Rodriguez Lopez

2010-03-08

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi!

I'm updating validations on my app to use AJAX. I followed this:

http://struts.apache.org/2.0.14/docs/ajax-validation.html

Using dojo and <sx:submit validate=true/> tag, on a tipical User form page.

The problem: When I click the submit button on the form, on the client
side nothing happens, not a message displayed, not a page reload or
request. On the server side, interceptors are called as they should,
JSONInterceptor is called, and if there where no errors, the correct
action and method (UserAction.save()) is called, so the data gets really
saved, when I manually go back to the listing of the users, the user
name got changed accordingly to the form. The only thing is that it
appears like nothing happened when pressing the submit button.

Validation worked OK before trying to implement AJAX validation. Using
Struts 2.1.8, already have on /lib the struts2-dojo-plugin and
<sx:head/> on my jsps.

Any help on this? Thanks in advance!

Alex

Code:

### edit.jsp ###

<s:form action="save" namespace="/user" method="POST">
     <s:token/>
     <s:hidden name="user.userID" />
     <s:textfield name="user.name" size="35" >
       <s:param name="label">
         <s:text name="label.name" />
       </s:param>
     </s:textfield>
     <s:textfield name="user.email" size="35" >
       <s:param name="label">
         <s:text name="label.email" />
       </s:param>
     </s:textfield>
     <s:textarea name="user.address" cols="32" >
       <s:param name="label">
         <s:text name="label.address" />
       </s:param>
     </s:textarea>
     
     <sx:submit validate="true" type="button" />
</s:form>

### user-mappings.xml ###

<package name="user"
      namespace="/user"
      extends="default">

<action name="*" method="{1}" class="package.action.user.UserAction">
 <result type="redirect">list.action</result>
 <result name="list">/WEB-INF/content/user/list.jsp</result>
 <result name="input">/WEB-INF/content/user/edit.jsp</result>
</action>

</package>

### UserAction.java ###

public String save() throws Exception {
 ServiceUser.getInstance().save(getUser());
 return SUCCESS;
}

// getter and setter for user and other stuff

### UserAction-save-validation.xml ###

<validators>
<field name="user.name">
 <field-validator type="requiredstring">
 <message>
 ${getText("error.required", {getText("label.name")})}
 </message>
 </field-validator>
</field>
<field name="user.email">
 <field-validator type="requiredstring">
 <message>
 ${getText("error.required", {getText("label.email")})}
 </message>
 </field-validator>
 <field-validator type="email">
 <message>${getText("error.format.email")}</message>
 </field-validator>
</field>
</validators>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 gg3721.com - Jax Systems, LLC, U.S.A.