Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

intermediate submit and validation of a form

 
Padmini Nagarajan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a jsp page with some fields say AA,XX , YY, ZZ
and 2 buttons say Submit and validate.
On click of submit button All fields AA,XX,YY and ZZ are mandatory
And on click of validate button only AA and ZZ are mandatory..
I know tht we can set different actions like this
document.forms[0].action='DDD.do'; and submit the form

I have enabled javascript validation for my form.. and need to trigger client side validation ..
With this senario, How do I define my validation.xml such tht user is prompted to fill the required fields on click of the respective buttons..
 
Steve Ziegler
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Padmini,

Have you looked into using a LookupDispatchAction to split up your Actions? All relevant code would look like this:

-----

public class YourDispatchAction extends LookupDispatchAction{
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("appProperty.submit","submit");
map.put("appProperty.validate","validate");
return map;
}
public ActionForward submit
(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
return mapping.findForward("submit");
}
public ActionForward validate
(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
return mapping.findForward("validate");
}
}

-----

In struts-config:

<action path="/YourDispatchAction" name="yourBeanName" parameter="method" type="packageName.YourDispatchAction">
<forward name="submit" path="/SubmitAction.do"/>
<forward name="validate" path="/ValidateAction.do"/>
</action>

-----
In jsp:

<html:form action="/YourDispatchAction">
...
<html:submit styleClass="submit" property="method">
<fmt:message key="appProperty.submit" />
</html:submit>
<html:submit styleClass="submit" property="method">
<fmt:message key="appProperty.validate" />
</html:submit>
...
</html:form>

-----
In ApplicationResources.properties:

appProperty.validate=Validate
appProperty.submit=Submit

-----

This way, you can use the LookupDispatchAction to branch to two other actions, SubmitAction and ValidateAction. Once you have that, you can just create different validations for those two seperate actions. Good luck!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic