You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Wes Rood <we...@myfastmail.com> on 2003/07/15 19:12:38 UTC

reusing same form for inserts and updates

I've searched the archives for this type of discussion but I'm not 
really finding what I want.

I'd like to reuse the same jsp form for both inserts and updates of a 
particular set of data.  My current solution is to come into the action 
with a flag of "new" or "edit".  If "edit", the action will fetch the 
existing data into the FormBean by the primary key (int) which is 
currently in the FormBean, then forward to the input view.  If "new", 
the action will just forward to the input view (thus the primary key is 0)

The input view is the jsp form, which has a hidden property set to the 
primary key of the FormBean.

The form is then submitted back to this action with a flag of "save", 
and then it will check for the presence of the primary key (from the 
hidden field), and do an insert or update based on whether or not it is > 0.

Another variation of this is to set a specific field in the FormBean 
instead of the primary key, but it is the same idea (still requires 
handling this field as a hidden field in the form)  Which I found at:
http://www.reumann.net/do/struts/lessons

I'd really like to clean this up a bit, hopefully by removing the 
requirement of setting a hidden property in the form.  One idea was to 
put the new/edit information into the session, but this fails if the 
user has 2 browser windows open, trying to do a new record in one window 
and an update in another (since they share the session).  Another idea 
was to attempt an update, and then fail back to an insert, or vice 
versa.  But that is an extra db hit.

Any suggestions or experiences would be helpful.  Thanks!




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


link tags and nesting

Posted by Michael Ruppin <mr...@yahoo.com>.
Is there a way to accomplish something resembling this
without scriptlet?:

<a href="Foo.do?Fooform.Foos[1].foo=BARepair"></a>
<a
href="Foo.do?Fooform.Foos[2].foo=BARecognition"></a>

The jsp rendering this is using a nested indexed
ActionForm, and the action mapped via Foo.do uses the
same nested indexed ActionForm.  I'm using the nested
taglib, but it doesn't appear as if there's a way to
automate the "paramId" like one would the "name" for a
tag rendering some <input> HTML.

m

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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


Re: reusing same form for inserts and updates

Posted by Wes Rood <we...@myfastmail.com>.
Woops... after thinking about this more, I realized that I *have* to put 
the primary key in the form somewhere, or I won't know what record to 
update... I'd still like to hear your experiences in this area though... 
Thanks

Wes Rood wrote:

> I've searched the archives for this type of discussion but I'm not 
> really finding what I want.
>
> I'd like to reuse the same jsp form for both inserts and updates of a 
> particular set of data.  My current solution is to come into the 
> action with a flag of "new" or "edit".  If "edit", the action will 
> fetch the existing data into the FormBean by the primary key (int) 
> which is currently in the FormBean, then forward to the input view.  
> If "new", the action will just forward to the input view (thus the 
> primary key is 0)
>
> The input view is the jsp form, which has a hidden property set to the 
> primary key of the FormBean.
>
> The form is then submitted back to this action with a flag of "save", 
> and then it will check for the presence of the primary key (from the 
> hidden field), and do an insert or update based on whether or not it 
> is > 0.
>
> Another variation of this is to set a specific field in the FormBean 
> instead of the primary key, but it is the same idea (still requires 
> handling this field as a hidden field in the form)  Which I found at:
> http://www.reumann.net/do/struts/lessons
>
> I'd really like to clean this up a bit, hopefully by removing the 
> requirement of setting a hidden property in the form.  One idea was to 
> put the new/edit information into the session, but this fails if the 
> user has 2 browser windows open, trying to do a new record in one 
> window and an update in another (since they share the session).  
> Another idea was to attempt an update, and then fail back to an 
> insert, or vice versa.  But that is an extra db hit.
>
> Any suggestions or experiences would be helpful.  Thanks!
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>


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


RE: reusing same form for inserts and updates

Posted by Mark Galbreath <ma...@qat.com>.
My primary keys are the email addresses of the users, and I always bring up
a blank form and allow the user to choose (radio buttons) to retrieve,
update, or submit new records based on date.  The userId is stored in
session scope at login.

Mark

-----Original Message-----
From: Wes Rood [mailto:wes9999@myfastmail.com] 
Sent: Tuesday, July 15, 2003 1:13 PM
To: Struts Users Mailing List
Subject: reusing same form for inserts and updates


I've searched the archives for this type of discussion but I'm not 
really finding what I want.

I'd like to reuse the same jsp form for both inserts and updates of a 
particular set of data.  My current solution is to come into the action 
with a flag of "new" or "edit".  If "edit", the action will fetch the 
existing data into the FormBean by the primary key (int) which is 
currently in the FormBean, then forward to the input view.  If "new", 
the action will just forward to the input view (thus the primary key is 0)

The input view is the jsp form, which has a hidden property set to the 
primary key of the FormBean.

The form is then submitted back to this action with a flag of "save", 
and then it will check for the presence of the primary key (from the 
hidden field), and do an insert or update based on whether or not it is > 0.

Another variation of this is to set a specific field in the FormBean 
instead of the primary key, but it is the same idea (still requires 
handling this field as a hidden field in the form)  Which I found at:
http://www.reumann.net/do/struts/lessons

I'd really like to clean this up a bit, hopefully by removing the 
requirement of setting a hidden property in the form.  One idea was to 
put the new/edit information into the session, but this fails if the 
user has 2 browser windows open, trying to do a new record in one window 
and an update in another (since they share the session).  Another idea 
was to attempt an update, and then fail back to an insert, or vice 
versa.  But that is an extra db hit.

Any suggestions or experiences would be helpful.  Thanks!




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




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