I'm still trying to understand this. Please be patient.

Here's my setup. I'm trying to create a test page that will do regression
tests against all the different parts of my internal systems.

I have one simple form (ActionForm) defined.

<form-bean name="CollectionForm"
type="org.apache.struts.action.DynaActionForm" >
  <form-property name="collection" type="java.util.Collection" />
</form-bean>

I have two actions that deal with this ...

<action path="/outputpage/testresults"
forward="/WEB-INF/jsp/testresults.jsp" />
<action path="/actions/runtests" type="org.loom.fe.actions.RunTestAction"
        name="CollectionForm" scope="request" >
        <forward name="results" path="/outputpage/testresults.do"
redirect="true" />
        <forward name="errror" ... />
</action>

So then in my execute of RunTestAction:

{
...
DynaActionForm dform = (DynaActionForm) form;

// create my test results and put them in the collection
Collection testResult = ... 

// put the collection into the outgoing form
dform.set( "collection", testResults);

// put the form into the right scope

request.getSession().setAttribute( "CollectionForm", dform);

// go to the results page
return (mapping.findForward( "results"));
}

To kick things off I have this in my admin screen:

<html:link action="/actions/runtests.do">Run Tests</html:link>

Then in my testresults.jsp:

<logic:present name="CollectionForm">
  <table>
   <logic:iterate id="result" name="CollectionForm" property="collection">
     <tr>
       <td><bean:write name="result" property= ... Test result ... /><td>
     <tr>
   </logic:iterate>
  </table>
</logic:present>

OK... Just to make sure we all understand, the above works! It works just
fine!
REPEAT: IT WORKS

However, I really don't like putting the CollectionForm that's going to my
results page being in the session scope. I'd much rather have it only in the
request scope of the results page. That way this CollectionForm doesn't
travel all around with the session. Of course I could manually remove it
from within the jsp page, but that would kill the whole point of MVC...
Right?

I've tried making two changes:
1. change the action for the results page
<action path="/outputpage/testresults"
forward="/WEB-INF/jsp/testresults.jsp" scope="request" />
2. change the scope of the variable for the CollectionForm in RunTestAction
request.setAttribute( "CollectionForm", dform);

That doesn't work. The CollectionForm is not available at all to the jsp.

Then I tried this:
1. change the action for the results page
<action path="/outputpage/testresults"
forward="/WEB-INF/jsp/testresults.jsp" name="CollectionForm" scope="request"
/>

This then make a CollectionForm available to the jsp but it was empty.. Not
the same one that I had linked to the request above.

It seems to me that really it shouldn't be able to work since the request
form my RunTestsAction is a totally different object than the request for
the jsp page. Thus the example from Hubert below wouldn't work in my mind.

So, bottom line... I can make what I'm trying to do work. But it just
doesn't feel right putting it into session scope. I can't believe that
no-one has had to deal with this before.




> -----Original Message-----
> From: Hubert Rabago [mailto:[EMAIL PROTECTED] 
> Sent: Friday, March 11, 2005 9:36 AM
> To: Struts Users Mailing List
> Subject: Re: Correct Prepopulate Method
> 
> 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 <[EMAIL PROTECTED]> 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#E
> > x1-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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to