intermediate submit and validation of a form
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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..
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..
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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!
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!
| She still doesn't approve of my superhero lifestyle. Or this shameless plug: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |









