You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Schuster Joel M Contr ESC/NDC <Jo...@cisf.af.mil> on 2005/03/11 17:18:15 UTC
Correct Prepopulate Method
I've read a number of articles about correct pre-populate forms methods,
including the following:
1. http://www.javaworld.com/javaworld/jw-09-2004/jw-0913-struts-p3.html
<http://www.javaworld.com/javaworld/jw-09-2004/jw-0913-struts-p3.html>
2. http://struts.apache.org/faqs/newbie.html#prepopulate
<http://struts.apache.org/faqs/newbie.html#prepopulate>
3.
http://www.coreservlets.com/Apache-Struts-Tutorial/Struts-Forms.html#Ex1-Ste
p1
<http://www.coreservlets.com/Apache-Struts-Tutorial/Struts-Forms.html#Ex1-St
ep1>
I have some questions.
The first article does not talk specifics about how Lazy-Loading would be
implemented.
The second doesn't talk about how the actual pre-population would be
implemented in the action.
And the third does it in a way that's different from how others do it.
Here's what I've gotten so far...
There are two different ways that I see to do it.
1. Load the FormBean up in the constructor.
a. This does not work in Dyna*Forms since there's no actual
implementation
b. This then moves the logic to the actual form bean which is not where
it's supposed to be.
2. Load the FormBean in a precursor Action
a. This works well but every example I've seen then does something like
this:
Request.getSession().setAttribute( '"formBean", bean);
This seems like a bad idea since it places the bean into the session scope.
I've tried doing this by putting it directly into request but of course the
jsp then doesn't have access to it because the request on the Action is not
in the same scope as the 'form'.jsp
So I guess I'm at a loss on how best to pre-populate Dyna*Forms. Examples
that have worked from your experience would be appreciated.
Re: Correct Prepopulate Method
Posted by Hubert Rabago <hr...@gmail.com>.
You would usually do prepopulation in a setup form. Which scope you
place the form in depends on how you configure the action that the
form will be submitted to. For example, if you have "/showPage.do"
and "/submitForm.do", where submitForm is configured as:
<action path="/submitForm" name="myForm" ...>....</action>
Then in the action for showPage, you'd:
ModuleConfig moduleConfig =
ModuleUtils.getInstance().getModuleConfig(request);
FormBeanConfig formBeanConfig = moduleConfig.findFormBeanConfig("myForm");
DynaActionForm myForm = (DynaActionForm)
formBeanConfig.createActionForm(getServlet());
myForm.set("propName",propValue);
request.getSession().setAttribute("myForm", myForm);
If you want to use request scope, change /submitForm to:
<action path="/submitForm" name="myForm" scope="request"...>....</action>
then in showPage:
request.setAttribute("myForm", myForm);
Hubert
On Fri, 11 Mar 2005 09:18:15 -0700, Schuster Joel M Contr ESC/NDC
<Jo...@cisf.af.mil> wrote:
> I've read a number of articles about correct pre-populate forms methods,
> including the following:
>
> 1. http://www.javaworld.com/javaworld/jw-09-2004/jw-0913-struts-p3.html
> <http://www.javaworld.com/javaworld/jw-09-2004/jw-0913-struts-p3.html>
> 2. http://struts.apache.org/faqs/newbie.html#prepopulate
> <http://struts.apache.org/faqs/newbie.html#prepopulate>
> 3.
> http://www.coreservlets.com/Apache-Struts-Tutorial/Struts-Forms.html#Ex1-Ste
> p1
> <http://www.coreservlets.com/Apache-Struts-Tutorial/Struts-Forms.html#Ex1-St
> ep1>
>
> I have some questions.
>
> The first article does not talk specifics about how Lazy-Loading would be
> implemented.
>
> The second doesn't talk about how the actual pre-population would be
> implemented in the action.
>
> And the third does it in a way that's different from how others do it.
>
> Here's what I've gotten so far...
>
> There are two different ways that I see to do it.
>
> 1. Load the FormBean up in the constructor.
>
> a. This does not work in Dyna*Forms since there's no actual
> implementation
> b. This then moves the logic to the actual form bean which is not where
> it's supposed to be.
>
> 2. Load the FormBean in a precursor Action
>
> a. This works well but every example I've seen then does something like
> this:
>
> Request.getSession().setAttribute( '"formBean", bean);
>
> This seems like a bad idea since it places the bean into the session scope.
> I've tried doing this by putting it directly into request but of course the
> jsp then doesn't have access to it because the request on the Action is not
> in the same scope as the 'form'.jsp
>
> So I guess I'm at a loss on how best to pre-populate Dyna*Forms. Examples
> that have worked from your experience would be appreciated.
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Correct Prepopulate Method
Posted by Dakota Jack <da...@gmail.com>.
Too bad ActionForms were called "ActionForms" rather than something
like "ActionData", "ActionState", or "ActionContext". The html pages
are "populated", I guess, with data. If you try to map ActionForms to
html or JSP forms, I think your whole way of looking at the problems
becomes completely skewed. Think of the form data as data and not as
some ghost of the form. The term "pre-populate", in my opinion, is
not very useful.
On Fri, 11 Mar 2005 09:18:15 -0700, Schuster Joel M Contr ESC/NDC
<Jo...@cisf.af.mil> wrote:
> I've read a number of articles about correct pre-populate forms methods,
> including the following:
>
> 1. http://www.javaworld.com/javaworld/jw-09-2004/jw-0913-struts-p3.html
> <http://www.javaworld.com/javaworld/jw-09-2004/jw-0913-struts-p3.html>
> 2. http://struts.apache.org/faqs/newbie.html#prepopulate
> <http://struts.apache.org/faqs/newbie.html#prepopulate>
> 3.
> http://www.coreservlets.com/Apache-Struts-Tutorial/Struts-Forms.html#Ex1-Ste
> p1
> <http://www.coreservlets.com/Apache-Struts-Tutorial/Struts-Forms.html#Ex1-St
> ep1>
>
> I have some questions.
>
> The first article does not talk specifics about how Lazy-Loading would be
> implemented.
>
> The second doesn't talk about how the actual pre-population would be
> implemented in the action.
>
> And the third does it in a way that's different from how others do it.
>
> Here's what I've gotten so far...
>
> There are two different ways that I see to do it.
>
> 1. Load the FormBean up in the constructor.
>
> a. This does not work in Dyna*Forms since there's no actual
> implementation
> b. This then moves the logic to the actual form bean which is not where
> it's supposed to be.
>
> 2. Load the FormBean in a precursor Action
>
> a. This works well but every example I've seen then does something like
> this:
>
> Request.getSession().setAttribute( '"formBean", bean);
>
> This seems like a bad idea since it places the bean into the session scope.
> I've tried doing this by putting it directly into request but of course the
> jsp then doesn't have access to it because the request on the Action is not
> in the same scope as the 'form'.jsp
>
> So I guess I'm at a loss on how best to pre-populate Dyna*Forms. Examples
> that have worked from your experience would be appreciated.
>
>
--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Correct Prepopulate Method
Posted by Joe Germuska <Jo...@Germuska.com>.
Hubert has already pretty well described good coding practice for
getting an ActionForm instance. Note that the pages you cited may
have been written before the FormBeanConfig object acted as a
factory, which is a relatively recent enhancement.
Really, though, I think there should probably be a method like:
getMeTheRightForm(ActionContext ctx, String name, String scope)
which deals with searching scopes, instantiating, and if necessary
placing the new instance into the right scope. I'm just not sure
where to put it. Perhaps an instance method on the ModuleConfig
interface?
Joe
--
Joe Germuska
Joe@Germuska.com
http://blog.germuska.com
"Narrow minds are weapons made for mass destruction" -The Ex
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org