You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by John Hogan <jh...@ireland.com> on 2001/06/06 23:28:41 UTC

ActionForm/Action with edit mode

All,

I have a situation where it is desirable to use a form/page for both 
adding new info and editing existing data.  The new info scenario is 
straight forward struts ActionForm/Action classes.  What I'm 
wrestling with a bit is the edit scenario.  I'm wondering if I can 
stay within the struts framework and still do something like entering 
a page in edit mode and have it displaying existing user data?

It seems this should be possible because that's exactly what the page 
does for error handling.  Has anyone else tackled this one yet?  TIA.

JohnH

_____________________________________

Get your free E-mail at http://www.ireland.com

Re: ActionForm/Action with edit mode

Posted by Ted Husted <hu...@apache.org>.
If I understand the question, all you have to do is change the form's
action to insert or update as the case may be. A good way to do this is
to have a "task" parameter that you would pass to a single action
designed to handle both cases. You can do this dymamically using (where
key=0 means we're inserting a new record). 

<logic:equal name="myForm" property="key" value="0">
<input type="hidden" name="task" value="insert">
</logic:equal>
<logic:notEqual name="myForm" property="key" value="0">
<input type="hidden" name="task" value="update">
</logic:notEqual>

For an update, visit an Action first, select the record, populate the
form, and forward to input.  

John Hogan wrote:
> 
> All,
> 
> I have a situation where it is desirable to use a form/page for both
> adding new info and editing existing data.  The new info scenario is
> straight forward struts ActionForm/Action classes.  What I'm
> wrestling with a bit is the edit scenario.  I'm wondering if I can
> stay within the struts framework and still do something like entering
> a page in edit mode and have it displaying existing user data?
> 
> It seems this should be possible because that's exactly what the page
> does for error handling.  Has anyone else tackled this one yet?  TIA.
> 
> JohnH
> 
> _____________________________________
> 
> Get your free E-mail at http://www.ireland.com

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 737-3463.
-- http://www.husted.com/about/struts/

Re: ActionForm/Action with edit mode

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 6 Jun 2001, John Hogan wrote:

> All,
> 
> I have a situation where it is desirable to use a form/page for both 
> adding new info and editing existing data.  The new info scenario is 
> straight forward struts ActionForm/Action classes.  What I'm 
> wrestling with a bit is the edit scenario.  I'm wondering if I can 
> stay within the struts framework and still do something like entering 
> a page in edit mode and have it displaying existing user data?
> 
> It seems this should be possible because that's exactly what the page 
> does for error handling.  Has anyone else tackled this one yet?  TIA.
> 
> JohnH
> 
> _____________________________________
> 
> Get your free E-mail at http://www.ireland.com
> 

The Struts example application includes logic that does exactly what you
describe -- the same page (subscription.jsp) is used to add new
subscriptions, edit old ones, and confirm deletion of old ones.  For the
edit case, the trick was to forward to an Action that created a form bean
prepopulated with the values from the database object, and then forward to
the page.

Craig