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:[EMAIL PROTECTED] 
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to