You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Christopher Kwiatkowski <ck...@uga.edu> on 2004/08/17 16:37:31 UTC

Dynamic Form Submission

I want to create a form that has two different actions.  The user will have
a button to “READ” information in from the database and a button to “SAVE”
information into the database after modification.  I currently use Validator
to validate my forms and when the user clicks on the “READ” button then
Validator takes over and gives the user errors.  I don’t want the form to be
validated when the user is attempting a “READ”.  I only want the form to be
validated if the user is attempting to do a “SAVE”.  Unless anyone has a
better solution (which I hope someone does), I have decided that I need to
create two action classes.  One that will handle the read logic without
going through validation and one that will handle the save logic and go
through the validation.  My question with this solution is how do I
elegantly provide this functionality on the jsp?  Do I put the “SAVE” submit
button within one form and the “READ” submit button within another form and
have different actions associated with each form?  Or, is there a better
way?
Thanks,
Christopher Kwiatkowski

Re: Dynamic Form Submission

Posted by Erik Weber <er...@mindspring.com>.
You can use the same Action and the same ActionForm, but you can map two 
different action mappings in struts-config.xml. Set validation to "true" 
on one and "false" on the other.

Hope that helps,
Erik


Christopher Kwiatkowski wrote:

>I want to create a form that has two different actions.  The user will have
>a button to “READ” information in from the database and a button to “SAVE”
>information into the database after modification.  I currently use Validator
>to validate my forms and when the user clicks on the “READ” button then
>Validator takes over and gives the user errors.  I don’t want the form to be
>validated when the user is attempting a “READ”.  I only want the form to be
>validated if the user is attempting to do a “SAVE”.  Unless anyone has a
>better solution (which I hope someone does), I have decided that I need to
>create two action classes.  One that will handle the read logic without
>going through validation and one that will handle the save logic and go
>through the validation.  My question with this solution is how do I
>elegantly provide this functionality on the jsp?  Do I put the “SAVE” submit
>button within one form and the “READ” submit button within another form and
>have different actions associated with each form?  Or, is there a better
>way?
>Thanks,
>Christopher Kwiatkowski
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Dynamic Form Submission

Posted by Bill Siggelkow <bi...@bellsouth.net>.
First, I assume that you are using path mappings for Validator.
You can use two separate forms as you suggested; however, if you don't 
want to duplicate form fields and it makes more sense from a usability 
perspective to have a single form--you can change the action for the 
form on the fly using JavaScript like the following:

--------------------------------------------------------------------
<script>
       function swapAction(control) {
         formAction = document.getElementById("empForm").action;
         if (control.checked)
           newAction = '<html:rewrite page="/CreateEmployee.do"/>';
         else
           newAction = '<html:rewrite page="/UpdateEmployee.do"/>';
         document.getElementById("empForm").action = newAction;
       }
</script>
<html:form styleId="empForm" action="/UpdateEmployee">
     New Employee: <html:checkbox property="create"
       onclick='swapAction(this)"'/><br />
     … rest of the page
--------------------------------------------------------------------

Christopher Kwiatkowski wrote:
> I want to create a form that has two different actions.  The user will have
> a button to “READ” information in from the database and a button to “SAVE”
> information into the database after modification.  I currently use Validator
> to validate my forms and when the user clicks on the “READ” button then
> Validator takes over and gives the user errors.  I don’t want the form to be
> validated when the user is attempting a “READ”.  I only want the form to be
> validated if the user is attempting to do a “SAVE”.  Unless anyone has a
> better solution (which I hope someone does), I have decided that I need to
> create two action classes.  One that will handle the read logic without
> going through validation and one that will handle the save logic and go
> through the validation.  My question with this solution is how do I
> elegantly provide this functionality on the jsp?  Do I put the “SAVE” submit
> button within one form and the “READ” submit button within another form and
> have different actions associated with each form?  Or, is there a better
> way?
> Thanks,
> Christopher Kwiatkowski
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Dynamic Form Submission

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Christopher Kwiatkowski wrote:

>I want to create a form that has two different actions.  The user will have
>a button to “READ” information in from the database and a button to “SAVE”
>information into the database after modification.  I currently use Validator
>to validate my forms and when the user clicks on the “READ” button then
>Validator takes over and gives the user errors.  I don’t want the form to be
>validated when the user is attempting a “READ”.  I only want the form to be
>validated if the user is attempting to do a “SAVE”.  Unless anyone has a
>better solution (which I hope someone does), I have decided that I need to
>create two action classes.  One that will handle the read logic without
>going through validation and one that will handle the save logic and go
>through the validation.  My question with this solution is how do I
>elegantly provide this functionality on the jsp?  Do I put the “SAVE” submit
>button within one form and the “READ” submit button within another form and
>have different actions associated with each form?  Or, is there a better
>way?
>Thanks,
>Christopher Kwiatkowski
>  
>
Lo, Christopher,

You might get some ideas from 
http://wiki.apache.org/struts/StrutsCatalogMultipleImageTagsSimplified

Michael



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Dynamic Form Submission

Posted by Bill Siggelkow <bi...@bellsouth.net>.
Oops -- I missformatted my last e-mail -- I wrote the part starting with 
"Ahh ..." not Marco. Marco wrote the stuff that followed about using 
DispatchAction. My bad ...



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Dynamic Form Submission

Posted by Bill Siggelkow <bi...@bellsouth.net>.
Marco Mistroni wrote:
Ahh ... but the poster said he was using Validator -- he could subclass 
ValidatorActionForm (or DynaValidatorActionForm) -- or he could get 
"fancy" (or "complicated" depending on your perspective) and use 
requiredif or validwhen against the field that indicated if it was READ 
or SAVE.

> Hello,
> 	How about using a DispatchAction triggered by a 
> Parameter, let's say 'buttonSelected', which would be
> Either insert/read/delete etc....
> 
> In ur validation you check for the value of that parameter in order
> To perform validation...
> 
> Hope this helps
> Regards
> 	marco
> 
> -----Original Message-----
> From: Christopher Kwiatkowski [mailto:ckwiat@uga.edu] 
> Sent: 17 August 2004 15:38
> To: user@struts.apache.org
> Subject: Dynamic Form Submission
> 
> I want to create a form that has two different actions.  The user will
> have
> a button to "READ" information in from the database and a button to
> "SAVE"
> information into the database after modification.  I currently use
> Validator
> to validate my forms and when the user clicks on the "READ" button then
> Validator takes over and gives the user errors.  I don't want the form
> to be
> validated when the user is attempting a "READ".  I only want the form to
> be
> validated if the user is attempting to do a "SAVE".  Unless anyone has a
> better solution (which I hope someone does), I have decided that I need
> to
> create two action classes.  One that will handle the read logic without
> going through validation and one that will handle the save logic and go
> through the validation.  My question with this solution is how do I
> elegantly provide this functionality on the jsp?  Do I put the "SAVE"
> submit
> button within one form and the "READ" submit button within another form
> and
> have different actions associated with each form?  Or, is there a better
> way?
> Thanks,
> Christopher Kwiatkowski


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Dynamic Form Submission

Posted by Marco Mistroni <mm...@waersystems.com>.
Hello,
	How about using a DispatchAction triggered by a 
Parameter, let's say 'buttonSelected', which would be
Either insert/read/delete etc....

In ur validation you check for the value of that parameter in order
To perform validation...

Hope this helps
Regards
	marco

-----Original Message-----
From: Christopher Kwiatkowski [mailto:ckwiat@uga.edu] 
Sent: 17 August 2004 15:38
To: user@struts.apache.org
Subject: Dynamic Form Submission

I want to create a form that has two different actions.  The user will
have
a button to "READ" information in from the database and a button to
"SAVE"
information into the database after modification.  I currently use
Validator
to validate my forms and when the user clicks on the "READ" button then
Validator takes over and gives the user errors.  I don't want the form
to be
validated when the user is attempting a "READ".  I only want the form to
be
validated if the user is attempting to do a "SAVE".  Unless anyone has a
better solution (which I hope someone does), I have decided that I need
to
create two action classes.  One that will handle the read logic without
going through validation and one that will handle the save logic and go
through the validation.  My question with this solution is how do I
elegantly provide this functionality on the jsp?  Do I put the "SAVE"
submit
button within one form and the "READ" submit button within another form
and
have different actions associated with each form?  Or, is there a better
way?
Thanks,
Christopher Kwiatkowski


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org