>The way this is typically handled is to use an Action to populate the 
>bean.  So instead of linking your user directly to the JSP page, you
link 
>them to an Action. 

Thanks for your response - i guess I arrived at the conclusion you
propose.  However I'm still unhappy with the notion that lots of forms
are going to need their own dedicated action just to initialize them.

Instead, I am experimenting with overriding the struts
processActionForm() to notice when the form is created and call a
form.create() method on my ActionForm subclass, passing the
request/session in at that time.  This seems to be working nicely - i
still have to have all requests for the page containing the form
accessed by an action to force initialization before the form is
displayed, but I have only one action class for all forms and the
initialization logic stays where it belongs - inside the form.

I'm curious if others think having a form.create() method would be
useful, and if so, if there is a possibiliy to incorporate it into the
struts core?  

I guess the signature would look like

  void create(HttpServletRequest request)

and it would be called each time a new action form bean instance is
created, on the instance created.

Cheers,

Simon.

-----Original Message-----
From: Michael McCallister [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 27, 2001 1:01 PM
To: [EMAIL PROTECTED]
Subject: Re: form initialization using session


The way this is typically handled is to use an Action to populate the 
bean.  So instead of linking your user directly to the JSP page, you
link 
them to an Action.  This Action typically loads the bean and then
returns 
the success mapping, which, in struts-config.xml, you've mapped to the
JSP 
that displays the values from the bean.

The example application that comes with struts shows how to do this.
The 
walking tour that accompanies the example explains it better than I 
have.  Look at the relationship between EditSubscriptionAction.java, 
subscription.jsp, and SaveSubscriptionAction.java.


Mike

At 11:46 AM 2/27/2001, you wrote:
>Hi all,
>
>I am working on an application where form fields need to default to
>values that depend on the user's profile, which is stored in the
>session.  Unfortunately, it seems like struts forms are created
>automatically without any hooks that allow access to the session to
>initialize these fields.
>
>The only thing that I can think of is to have our application
>proactively place the forms into the session with values initialized,
>possibly to have the form page link through an action which creates and
>initializes the form.  However this abandons the utility of having
>struts automatically create the forms for us - one of the many nice
>things about struts!
>
>This seems to me like it would be a common problem.  Does anyone have a
>good solution for it?
>
>Cheers,
>
>Simon.

Reply via email to