struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wes Rood <>
Subject reusing same form for inserts and updates
Date Tue, 15 Jul 2003 17:12:38 GMT
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:

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:
For additional commands, e-mail:

View raw message