• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

intermediate submit and validation of a form

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic