struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Jouravlev" <jmi...@gmail.com>
Subject Re: Session lovers... how do you handle this 'common?' situation?
Date Sun, 23 Apr 2006 03:26:58 GMT
Since your forms are stateful, you can have a mode/status field with
either "view existing" or "edit existing" or "create new" or "empty".

You will have two clear phases: on input phase you send "create"
message, clear form and set status to "create new". Since you use
session scope, you can safely use redirect. You redirect to an action
that renders your object according to its state. So, for "create new"
it will render input form with "New item" header.

I use nested objects in the actionform and simply create a new
business object for "create new" operation.

So, whenever you navigate to your render action, it will check current
status and show an appropriate page.

Editing is the same, but you do not clean the form. Render works the
same, but the header says "update item". The idea is that you handle
create and update operations using the same render/submit code, you
only initialize form differently.

If interested, see Struts Dialogs sample:
https://sourceforge.net/project/showfiles.php?group_id=49385&package_id=154597

Also see http://wiki.apache.org/struts/DataEntryForm

Michael.

On 4/21/06, Rick Reumann <rickcr@gmail.com> wrote:
> I haven't used Session scope for my ActionForms in a lonnnngggg time,
> but now I need to for a particular scenario.
>
> The problem I'm running into is imagine you click on a link to "Create
> New" - in which case, after you pass through your Action, you'd go to
> a page backed by the session-scoped ActionForm. If the ActionForm has
> stuff already in it, form say an edit process done earlier, this will
> show up on your form which isn't what you want in a "create new"
> sencario. To avoid this on the "new" situations I thought I could just
> hava a setUpForNew(..) dispatch method and do something like...
>
> public ActionForward setUpForNew(ActionMapping mapping, ActionForm form, ...{
>   form = new MyForm();
>   //maybe set a few things before I leave
>   //return
> }
>
> Then I mistakingly thought when I return to my JSP, the backing
> ActionForm would be pointing to this new ActionForm instance and all
> my properties would be set to their defaults.
>
> However, that above apparently is not working and I think I remember
> way back running into this and I think I remember the problem maybe
> being related to that the form bean referenced in my action method
> isn't really a true reference to the one that is actually in Session
> scope .. I think Struts does some funky stuff behind the scenes..
> can't remember all the details.
>
> So for those of you that use Session scope a lot, what is the easiest
> way to get a 'blank reset' form? Obviously I could go and reset every
> single property in the reset method and call that from my Action, but
> that seems like a lot of work and could get sloppy and introduce
> errors (later on you forget to reset a prop there etc).
>
> Am I totally missing something simple to accomplish what I want?
>
> Thanks,
>
> --
> Rick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


Mime
View raw message