RE: Validation + multiple Submit buttons
This works perfectly, a simple action to check which submit button is clicked forwards the three pages without validation to appropriate location. Actual Save button calls a commit action where validation is required. Thanks for the help Andrew -Oorspronkelijk bericht- Van: Christopher Schultz [mailto:[EMAIL PROTECTED] Verzonden: dinsdag 14 november 2006 15:37 Aan: Struts Users Mailing List Onderwerp: Re: Validation + multiple Submit buttons -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Andrew, Andrew Martin wrote: > That would be one solution, but in my case I have 4 submit buttons, > two of which redirect the user to another action (keeping scope set to > session) > and then back to the original form. Hmm... that makes things more interesting. How about this: You create a new action called "figureItOutAction" or something like that, and POST your form to that action. This action has no form bean, no validation, no nuthin'. In that action, you look for the names of the buttons that you want to use, say: SAVE, BACK, CANCEL, and FOURTH_BUTTON (or whatever). Then, you dispatch based upon the button that was pressed: in struts-config.xml: . . . Remember to definitely NOT set redirect="true", since we need the reques to stay in tact. Your code for FigureItOutAction will look like this: if(null != request.getParameter("save")) return mapping.findForward("save"); else if(null != request.getParameter("back")) return mapping.findForward("back"); . . . Then, just point each of these dispatching actions to the ones that really do the work. Each of these may have validation, form beans, etc. For instance, your "save" action (or "next"... whatever) will have a form bean and validate="true" in struts-config.xml. This trick allows you to submit your form to an action which decides what to do independently of validation. Forwarding on to another action that /does/ validate will then give you the magic of validation. I haven't tried this before, but it should work. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFWdRw9CaO5/Lv0PARAra+AJ9zZ4ejuncDFJXlQHicNXykEh9EWACgqTBJ GTAT1awgUG4RugUt/9jQNmw= =jcpP -END PGP SIGNATURE- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validation + multiple Submit buttons
Andrew Martin wrote: Maybe a stupid question but is it possible to call the specifc XML configuration from within the action? Yup, just set up your validation as usual, then set validate="false" on the action mapping and call the validation by hand: ActionMessages errors = form.validate(); That'll run the same validation machinery as Struts calls when validate is set to true. L. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validation + multiple Submit buttons
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Andrew, Andrew Martin wrote: > That would be one solution, but in my case I have 4 submit buttons, > two of which redirect the user to another action (keeping scope set to > session) > and then back to the original form. Hmm... that makes things more interesting. How about this: You create a new action called "figureItOutAction" or something like that, and POST your form to that action. This action has no form bean, no validation, no nuthin'. In that action, you look for the names of the buttons that you want to use, say: SAVE, BACK, CANCEL, and FOURTH_BUTTON (or whatever). Then, you dispatch based upon the button that was pressed: in struts-config.xml: . . . Remember to definitely NOT set redirect="true", since we need the reques to stay in tact. Your code for FigureItOutAction will look like this: if(null != request.getParameter("save")) return mapping.findForward("save"); else if(null != request.getParameter("back")) return mapping.findForward("back"); . . . Then, just point each of these dispatching actions to the ones that really do the work. Each of these may have validation, form beans, etc. For instance, your "save" action (or "next"... whatever) will have a form bean and validate="true" in struts-config.xml. This trick allows you to submit your form to an action which decides what to do independently of validation. Forwarding on to another action that /does/ validate will then give you the magic of validation. I haven't tried this before, but it should work. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFWdRw9CaO5/Lv0PARAra+AJ9zZ4ejuncDFJXlQHicNXykEh9EWACgqTBJ GTAT1awgUG4RugUt/9jQNmw= =jcpP -END PGP SIGNATURE- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validation + multiple Submit buttons
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Lance, Lance Semmens wrote: > A JS free application? You can assume today's browsers have > javascript, the web would break otherwise. Sure there are some cross > platform issues but to go JS free is a tall order and will limit you > to a clunky UI. I disagree. I think that JS is nice to use in order to improve the user experience, but relying on it to work is a recipe for disaster. Even if JS is available and enabled in the browser, sometimes things just don't work properly (new patch to the JS library or whatever) and your site stops cold. I recommend using JS as an improvement, not as a requirement. Just my perspective. > If JS free is your direction, you could wrap your back button in a > that posts to a different action to your save. That's not going to work, as the form can't have two targets. If you wrap the button in another form, you'll have to use JS to copy the values from one form to another. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFWdNU9CaO5/Lv0PARAjY1AKCCGsILCwM8mPxNOuJ21x8NjtWecgCfecxC 93wu48nVTO6ZaXUfx0tPzZM= =9WpP -END PGP SIGNATURE- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Validation + multiple Submit buttons
Thats what I thought myself, although it would be nice to be able to configure this independently within the xml configuration. Maybe a stupid question but is it possible to call the specifc XML configuration from within the action? -Oorspronkelijk bericht- Van: Ed Griebel [mailto:[EMAIL PROTECTED] Verzonden: dinsdag 14 november 2006 15:20 Aan: Struts Users Mailing List Onderwerp: Re: Validation + multiple Submit buttons You could turn off automatic validation in struts-config.xml and call it manually in the action method when you need validation. If you are using a recent version of Struts you can use LookupDispatchAction that will call a given method based on which button was pressed. http://struts.apache.org/1.2.7/api/org/apache/struts/actions/LookupDispatchAction.html HTH, -ed On 11/14/06, Andrew Martin <[EMAIL PROTECTED]> wrote: > JS Free, clunky UI you don't have to tell us! But those are the > restrictions we are working on. > It basically means additional actions/forms/JSP's when we want to do anything > of consequence. Usability is a big issue, but we can't do anyting about it. > > I don't think wrapping (nested) forms will actually work. certain form > buttons are located in the middle of the 'main' form as they cater for a > select option to another page. > > > > -Oorspronkelijk bericht- > Van: Lance Semmens [mailto:[EMAIL PROTECTED] > Verzonden: dinsdag 14 november 2006 14:54 > Aan: 'Struts Users Mailing List' > Onderwerp: RE: Validation + multiple Submit buttons > > > A JS free application? You can assume today's browsers have javascript, the > web would break otherwise. Sure there are some cross platform issues but to > go JS free is a tall order and will limit you to a clunky UI. > > If JS free is your direction, you could wrap your back button in a > that posts to a different action to your save. > > Lance. > > -Original Message- > From: Andrew Martin [mailto:[EMAIL PROTECTED] > Sent: 14 November 2006 13:36 > To: Struts Users Mailing List > Subject: Validation + multiple Submit buttons > > Hi, > > I have just begun to add validation to my forms using struts validator, which > is quite nice. I have however a problem when I have more than one submit > button on a form. > > For example I have a Save button and a Back button. > The Back button is also a submit (instead of a standard button - basically > because we are creating a JS free applciation!) > > Within the struts configuration the validate is set to true for this action > with an input page defined. > The validation is set to check certain fields are not empty. > > As both buttons call the same action the validation is called on both, but I > do not want validation to occur on certain submit actions (namely the Back > button) > > Ideally I would like to configure this in the XML Struts-config.xml or > validation.xml but I am not sure if this is actually possible (I fear the > worst) > > If anyone has any tips, much appreciated. > > Andrew > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validation + multiple Submit buttons
Use a Cancel button http://struts.apache.org/1.x/struts-taglib/tlddoc/html/cancel.html from javadoc Renders an HTML element of type submit. This tag is only valid when nested inside a form tag body. Pressing of this submit button causes the action servlet to bypass calling the associated form bean validate() method. The action is called normally. see also http://wiki.apache.org/struts/StrutsUpgradeNotes128to129 mas Andrew Martin wrote: Hi, I have just begun to add validation to my forms using struts validator, which is quite nice. I have however a problem when I have more than one submit button on a form. For example I have a Save button and a Back button. The Back button is also a submit (instead of a standard button - basically because we are creating a JS free applciation!) Within the struts configuration the validate is set to true for this action with an input page defined. The validation is set to check certain fields are not empty. As both buttons call the same action the validation is called on both, but I do not want validation to occur on certain submit actions (namely the Back button) Ideally I would like to configure this in the XML Struts-config.xml or validation.xml but I am not sure if this is actually possible (I fear the worst) If anyone has any tips, much appreciated. Andrew -- Mark Shifman MD. Ph.D. Yale Center for Medical Informatics Phone (203)737-5219 [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validation + multiple Submit buttons
You could turn off automatic validation in struts-config.xml and call it manually in the action method when you need validation. If you are using a recent version of Struts you can use LookupDispatchAction that will call a given method based on which button was pressed. http://struts.apache.org/1.2.7/api/org/apache/struts/actions/LookupDispatchAction.html HTH, -ed On 11/14/06, Andrew Martin <[EMAIL PROTECTED]> wrote: JS Free, clunky UI you don't have to tell us! But those are the restrictions we are working on. It basically means additional actions/forms/JSP's when we want to do anything of consequence. Usability is a big issue, but we can't do anyting about it. I don't think wrapping (nested) forms will actually work. certain form buttons are located in the middle of the 'main' form as they cater for a select option to another page. -Oorspronkelijk bericht- Van: Lance Semmens [mailto:[EMAIL PROTECTED] Verzonden: dinsdag 14 november 2006 14:54 Aan: 'Struts Users Mailing List' Onderwerp: RE: Validation + multiple Submit buttons A JS free application? You can assume today's browsers have javascript, the web would break otherwise. Sure there are some cross platform issues but to go JS free is a tall order and will limit you to a clunky UI. If JS free is your direction, you could wrap your back button in a that posts to a different action to your save. Lance. -Original Message- From: Andrew Martin [mailto:[EMAIL PROTECTED] Sent: 14 November 2006 13:36 To: Struts Users Mailing List Subject: Validation + multiple Submit buttons Hi, I have just begun to add validation to my forms using struts validator, which is quite nice. I have however a problem when I have more than one submit button on a form. For example I have a Save button and a Back button. The Back button is also a submit (instead of a standard button - basically because we are creating a JS free applciation!) Within the struts configuration the validate is set to true for this action with an input page defined. The validation is set to check certain fields are not empty. As both buttons call the same action the validation is called on both, but I do not want validation to occur on certain submit actions (namely the Back button) Ideally I would like to configure this in the XML Struts-config.xml or validation.xml but I am not sure if this is actually possible (I fear the worst) If anyone has any tips, much appreciated. Andrew - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Validation + multiple Submit buttons
JS Free, clunky UI you don't have to tell us! But those are the restrictions we are working on. It basically means additional actions/forms/JSP's when we want to do anything of consequence. Usability is a big issue, but we can't do anyting about it. I don't think wrapping (nested) forms will actually work. certain form buttons are located in the middle of the 'main' form as they cater for a select option to another page. -Oorspronkelijk bericht- Van: Lance Semmens [mailto:[EMAIL PROTECTED] Verzonden: dinsdag 14 november 2006 14:54 Aan: 'Struts Users Mailing List' Onderwerp: RE: Validation + multiple Submit buttons A JS free application? You can assume today's browsers have javascript, the web would break otherwise. Sure there are some cross platform issues but to go JS free is a tall order and will limit you to a clunky UI. If JS free is your direction, you could wrap your back button in a that posts to a different action to your save. Lance. -Original Message- From: Andrew Martin [mailto:[EMAIL PROTECTED] Sent: 14 November 2006 13:36 To: Struts Users Mailing List Subject: Validation + multiple Submit buttons Hi, I have just begun to add validation to my forms using struts validator, which is quite nice. I have however a problem when I have more than one submit button on a form. For example I have a Save button and a Back button. The Back button is also a submit (instead of a standard button - basically because we are creating a JS free applciation!) Within the struts configuration the validate is set to true for this action with an input page defined. The validation is set to check certain fields are not empty. As both buttons call the same action the validation is called on both, but I do not want validation to occur on certain submit actions (namely the Back button) Ideally I would like to configure this in the XML Struts-config.xml or validation.xml but I am not sure if this is actually possible (I fear the worst) If anyone has any tips, much appreciated. Andrew - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Validation + multiple Submit buttons
A JS free application? You can assume today's browsers have javascript, the web would break otherwise. Sure there are some cross platform issues but to go JS free is a tall order and will limit you to a clunky UI. If JS free is your direction, you could wrap your back button in a that posts to a different action to your save. Lance. -Original Message- From: Andrew Martin [mailto:[EMAIL PROTECTED] Sent: 14 November 2006 13:36 To: Struts Users Mailing List Subject: Validation + multiple Submit buttons Hi, I have just begun to add validation to my forms using struts validator, which is quite nice. I have however a problem when I have more than one submit button on a form. For example I have a Save button and a Back button. The Back button is also a submit (instead of a standard button - basically because we are creating a JS free applciation!) Within the struts configuration the validate is set to true for this action with an input page defined. The validation is set to check certain fields are not empty. As both buttons call the same action the validation is called on both, but I do not want validation to occur on certain submit actions (namely the Back button) Ideally I would like to configure this in the XML Struts-config.xml or validation.xml but I am not sure if this is actually possible (I fear the worst) If anyone has any tips, much appreciated. Andrew - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validation + multiple Submit buttons
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Andrew, Andrew Martin wrote: > I have just begun to add validation to my forms using struts > validator, which is quite nice. I have however a problem when I have > more than one submit button on a form. > > For example I have a Save button and a Back button. The Back button > is also a submit (instead of a standard button - basically because we > are creating a JS free applciation!) > > Within the struts configuration the validate is set to true for this > action with an input page defined. The validation is set to check > certain fields are not empty. What you want to do is to set your back button to be a "cancel" button. This is done differently depending on which content-builder you are using (JSP, Velocity, or whatever), but basically you have to end up naming the button "org.apache.struts.taglib.html.CANCEL", which indicates to struts that validation should be skipped. (Note that struts 1.2.7 (?) and higher require you to set a property for each action mapping that indicates that the action is cancellable). Note that, even though the validation is skipped, the form bean being used for validation is *still* filled with this non-validated data. If you are using a multi-page form bean, this is ideal: the user goes BACK, changes something on the previous page, and then when they come forward, again, you can redisplay the information they already entered into the form. Once they submit *that*, you perform the validation and move on. Of course, if you want BACK, NEXT, and CANCEL buttons on the page, then you can't really use this solution. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFWckq9CaO5/Lv0PARAjU2AJsHj3tDfnajq4v6FlOm+IW3hXabkwCfUXXm HOv3KWS1mMon6Bbn32qnbCo= =iLZY -END PGP SIGNATURE- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Validation + multiple Submit buttons
That is actually not too far off what I have at the moment, except I currently use to saveAction for all the submit values I will give it a go. Thanks. -Oorspronkelijk bericht- Van: Christopher Schultz [mailto:[EMAIL PROTECTED] Verzonden: dinsdag 14 november 2006 15:37 Aan: Struts Users Mailing List Onderwerp: Re: Validation + multiple Submit buttons -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Andrew, Andrew Martin wrote: > That would be one solution, but in my case I have 4 submit buttons, > two of which redirect the user to another action (keeping scope set to > session) > and then back to the original form. Hmm... that makes things more interesting. How about this: You create a new action called "figureItOutAction" or something like that, and POST your form to that action. This action has no form bean, no validation, no nuthin'. In that action, you look for the names of the buttons that you want to use, say: SAVE, BACK, CANCEL, and FOURTH_BUTTON (or whatever). Then, you dispatch based upon the button that was pressed: in struts-config.xml: . . . Remember to definitely NOT set redirect="true", since we need the reques to stay in tact. Your code for FigureItOutAction will look like this: if(null != request.getParameter("save")) return mapping.findForward("save"); else if(null != request.getParameter("back")) return mapping.findForward("back"); . . . Then, just point each of these dispatching actions to the ones that really do the work. Each of these may have validation, form beans, etc. For instance, your "save" action (or "next"... whatever) will have a form bean and validate="true" in struts-config.xml. This trick allows you to submit your form to an action which decides what to do independently of validation. Forwarding on to another action that /does/ validate will then give you the magic of validation. I haven't tried this before, but it should work. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFWdRw9CaO5/Lv0PARAra+AJ9zZ4ejuncDFJXlQHicNXykEh9EWACgqTBJ GTAT1awgUG4RugUt/9jQNmw= =jcpP -END PGP SIGNATURE- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Validation + multiple Submit buttons
That would be one solution, but in my case I have 4 submit buttons, two of which redirect the user to another action (keeping scope set to session) and then back to the original form. I do not want the validation to be carried out either of these two buttons but only on the SAVE submit button. (if that make sense!) -Oorspronkelijk bericht- Van: Christopher Schultz [mailto:[EMAIL PROTECTED] Verzonden: dinsdag 14 november 2006 14:48 Aan: Struts Users Mailing List Onderwerp: Re: Validation + multiple Submit buttons -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Andrew, Andrew Martin wrote: > I have just begun to add validation to my forms using struts > validator, which is quite nice. I have however a problem when I have > more than one submit button on a form. > > For example I have a Save button and a Back button. The Back button > is also a submit (instead of a standard button - basically because we > are creating a JS free applciation!) > > Within the struts configuration the validate is set to true for this > action with an input page defined. The validation is set to check > certain fields are not empty. What you want to do is to set your back button to be a "cancel" button. This is done differently depending on which content-builder you are using (JSP, Velocity, or whatever), but basically you have to end up naming the button "org.apache.struts.taglib.html.CANCEL", which indicates to struts that validation should be skipped. (Note that struts 1.2.7 (?) and higher require you to set a property for each action mapping that indicates that the action is cancellable). Note that, even though the validation is skipped, the form bean being used for validation is *still* filled with this non-validated data. If you are using a multi-page form bean, this is ideal: the user goes BACK, changes something on the previous page, and then when they come forward, again, you can redisplay the information they already entered into the form. Once they submit *that*, you perform the validation and move on. Of course, if you want BACK, NEXT, and CANCEL buttons on the page, then you can't really use this solution. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.5 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFWckq9CaO5/Lv0PARAjU2AJsHj3tDfnajq4v6FlOm+IW3hXabkwCfUXXm HOv3KWS1mMon6Bbn32qnbCo= =iLZY -END PGP SIGNATURE- - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]