Hello Greg,

Struts encourages you to use slight different yet powerful
approach. If you have a jsp page with a form it's nice to
have two actions to serve this form. One action is used
to prepare data for form (direct db access, ejb, xml, text file,
whatever you want) and another to collect info user entered
and process it (put into db and so on). Let's call these actions
"EditAction" and "SaveAction". So you're saying user can see
you page either during creating a widget or updating it.
Excellent, there is no need for any other action, just use
parameter(s) which will tell you the nature of the action,
in Struts example this parameter even called this way - "action".
So, you want to create something, you have a link like
'/EditSomething.do?action="Create"', you want update -
'/EditSomething.do?action="Update"', delete -
'/EditSomething.do?action="Delete"', other process -
'/EditSomething.do?action="other process"'. In your jsp form you write a
statement like this
<html:hidden property="action"/> and in your SaveAction you read
this parameter and act accordingly.

Eventually we end up having only one Edit and one Save actions
to do what ever we please with some item.

Best of luck,
Yuriy Zubarev



--- Greg Maletic <[EMAIL PROTECTED]> wrote:
> I have a JSP that is used to edit data on a ActionForm bean.  There are
> two
> ways for users to reach this JSP:  1) if they're adding a new object
> into my
> app; 2) if they're editing an existing object in my app.  I'm using two
> mappings in my struts-config.xml file to represent these two types of
> actions ("/add" and "/edit"), although they both map to this same JSP.
> (Additionally, the "/edit" mapping has a parameter called "productId"
> that
> describes which product to edit, while the "/add" mapping doesn't have a
> parameter.)
> 
> It's the behavior when the JSP's form is submitted that I'm having
> trouble
> with.  If the JSP was reached through the "add" mapping, I want it to go
> to
> an "/addExecute" mapping that will actually add the object.  And if the
> JSP
> was reached through the "edit" mapping, I want the form to go to an
> "/editExecute" mapping that will actually make the modifications to the
> object.  (As above, the "/editExecute" mapping needs a "productId"
> parameter
> specified--passed through from the original "/edit" mapping--while the
> "/addExecute" mapping doesn't.)  Unfortunately, I can't figure out how
> to
> conditionally make the form submit to one of two different actions
> ("/addExecute" or "/editExecute").
> 
> Is there a way to make this work?  Is this the right technique for
> solving
> this problem?  If not, could someone please let me know how this is
> typically done?
> 
> Thanks!
> 
> Greg
> 


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Reply via email to