Re: one more prepopulate question

2003-03-01 Thread Dan Allen
Perhaps populating at least 2 forms on the same page could be an
example for the struts distribution (or maybe in the FAQ).  Given
that I will be setting up my two forms soon, perhaps I can do a
short writeup on it after I collect the information, but given my
short experience with struts, maybe this would be better addressed
by a more veteraned user.

I just see this whole multiple-form prepopulate question cropping up
time and again on this list if we don't have something in the FAQ
about it.

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, [EMAIL PROTECTED]
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
When you're raised by the Jesuits, you become either obedient 
or impertinent 
 -- Jack McCoy, Law and Order
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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



Re: one more prepopulate question

2003-03-01 Thread Rick Reumann
On Sat, Mar 01,'03 (02:23 AM GMT-0600), Dan wrote: 
 ore veteraned user.
 
 I just see this whole multiple-form prepopulate question cropping up
 time and again on this list if we don't have something in the FAQ
 about it.

Coupled with the tidbits someone posted from Craig's snipet what
would be wrong with this approach: 

You have an Action class that you want to use to prepopulate three
Action Forms and then forward to a JSP page and set up three separate
forms. So you might have a mapping...

action path=/setupMultipleForms
type=foo.bar.SetUpFormsAction
name=form1
scope=request
validate=false

forward
name=continue
path=/severalFormsOnAPage.jsp/
/action

So now in the SetUpFormsAction you can easily put Form1 into scope by:
 
Form1 form1 = (Form1)form;
form1.setFoo(hello);
request.setAttribute(mapping.getAttribute(), form1 );

But now for another ActionForm (Form2) to put into scope you could do:

But probably better would be to use what I think I gleamed Craig
mention: (assuming form2 is tied to /foo in mapping):

ApplicationConfig appConfig = (ApplicationConfig)
request.getAttribute(Globals.APPLICATION_KEY);
ActionConfig actionConfig = appConfig.findActionConfig(/foo);
String name = actionConfig.getName(); // Form bean name

Form2 form2 = new Form2();
form2.setFooBar(BLA);
request.setAttribute( name, form2 );

for form3...

actionConfig = appConfig.findActionConfig(/fooForm3Action);
name = actionConfig.getName(); // Form bean name
Form3 form3 = new Form3();
form3.setBoo(hello world);
request.setAttribute( name, form3 );



Then on the JSP page you just use the html:form tags as you normally
would if there was just one form on the page.

-- 
Rick

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



RE: one more prepopulate question

2003-02-28 Thread Sri Sankaran
Here's what you are trying to do

  index.jsp 
- redirects to
  index.do
- needs to build a bunch'o forms
- forwards to
  home.jsp

Am I understanding you correctly?

The action corresponding to the path index can create any number of form-beans and 
persist them in any scope before forwarding to home.jsp.  Now home.jsp, has several 
html:forms; which implicitly means that it expects several form-beans.  These are 
available courtesy the aforementioned action.

Where are you running into a problem?

Sri

-Original Message-
From: Dan Allen [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 26, 2003 7:52 PM
To: [EMAIL PROTECTED]
Subject: one more prepopulate question


I know that the prepopulate question has been beaten into the ground around here and 
the answer on the FAQ page is complete in answering most questions I have about the 
concept.  But I just want to run something by this list, see if I am going about it in 
the right way.

When you are designing an application, and the index page has several mini-forms (such 
as a limited search, a login and maybe a site index) the first page has to be a *.do 
page.  So I figured, make an index.jsp page with

logic:redirect page=/index.do/

Then my /index action would prepare the forms and display /home.jsp. The FAQ talks 
about putting the form population in the Action class for the /index action, which 
works great...

...except, how would you populate more than one form?  Seems like in the cast you 
limit yourself to the form defined in the action mapping.  Would it be necessary to 
just set up an action chain?

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, [EMAIL PROTECTED]
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Real programmers just hate to get up in the morning, and 
contrary to Ordinary People, they're in better shape as 
it gets closer to nighttime.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

-
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]



Re: one more prepopulate question

2003-02-28 Thread Rick Reumann
On Fri, 28 Feb 2003 12:50:56 -0500
Sri Sankaran [EMAIL PROTECTED] wrote:
 
 Where are you running into a problem?

I think the initial problem was how you would pre-populate several
ActionForms inside of one Action and then be able to use those
ActionForms to create several forms in the resulting JSP page.

From what I can gather this is not too difficult as all you would do is
create as many ActionForm instances as you need in your SetupAction and
then put them all into request scope. You then can set up multiple forms
as you see fit on the fowarded to JSP page. 

The only thing I haven't found a nice work around for is that you can
only use one mapping.getAttribute() call in the Action for the form
associated with that Action. In example will help.

You have an Action class that you want to use to prepopulate three
Action Forms and then forward to a JSP page and set up three separate
forms. So you might have a mapping...

action path=/setupMultipleForms
type=foo.bar.SetUpFormsAction
name=form1
scope=request
validate=false

forward
name=continue
path=/severalFormsOnAPage.jsp/
/action

So now in the SetUpFormsAction you can easily put Form1 into scope by:
 
Form1 form1 = (Form1)form;
form1.setFoo(hello);
request.setAttribute(mapping.getAttribute(), form1 );

But now for another ActionForm (Form2) to put into scope you'd have
Form2 form2 = new Form2();
form2.setFooBar(BLA);
request.setAttribute( form2, form2 );

The part I don't like is you now have to remember that you need to
remember that you HAVE to refer to your Form2 object as form2 in your
mapping set up in your struts-config.xml file or else you JSP page will
not be able to find it. It's not a super big deal, but a bit annoying. 
Maybe there is another way to do it that I'm missing.


-- 
Rick Reumann

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



RE: one more prepopulate question

2003-02-28 Thread Sri Sankaran
 action path=/setupMultipleForms
 type=foo.bar.SetUpFormsAction
 name=form1
 scope=request
 validate=false
 
 forward
 name=continue
 path=/severalFormsOnAPage.jsp/
 /action
 
 So now in the SetUpFormsAction you can easily put Form1 into scope by:
  
 Form1 form1 = (Form1)form;
 form1.setFoo(hello);
 request.setAttribute(mapping.getAttribute(), form1 );

Actually, unless you are going (back) to a page that contains a form with action of 
setupMultipleForms you can't use this strategy.

What you actually need to know is the name attribute of the action mapping 
corresponding to the page to which the user is being directed *next*.  However, this 
isn't the end of the world; you can programmatically figure the name of the form-bean 
etc as follows:

  ApplicationConfig appConfig = (ApplicationConfig)
request.getAttribute(Globals.APPLICATION_KEY);
  ActionConfig actionConfig = appConfig.findActionConfig(/foo);
  String name = actionConfig.getName(); // Form bean name
  String attribute = actionConfig.getAttribute(); // Attribute to store under
  String scope = actionConfig.getScope(); // Scope to store in
  FormBeanConfig fbConfig = appConfig.findFormBeanConfig(name);

Now you've got all the metadata you need to dynamically instantiate the
appropriate form bean, and store it under the appropriate attribute in the
appropriate scope, without hard coding any of this stuff.

This is a snippet that Craig wrote up in response to an earlier post. 


Sri

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



RE: one more prepopulate question

2003-02-28 Thread Jayaraman Dorai
In the home page we have, where more than one form is required, we have used frames.  
The frames src points to action which prepopulates the form and is displayed in the 
jsp. Which also means there is a separate jsp page for each form.

Jayaraman  

-Original Message-
From: Rick Reumann [mailto:[EMAIL PROTECTED]
Sent: Friday, February 28, 2003 2:56 PM
To: Struts Users Mailing List
Subject: Re: one more prepopulate question


On Fri, 28 Feb 2003 12:50:56 -0500
Sri Sankaran [EMAIL PROTECTED] wrote:
 
 Where are you running into a problem?

I think the initial problem was how you would pre-populate several
ActionForms inside of one Action and then be able to use those
ActionForms to create several forms in the resulting JSP page.

From what I can gather this is not too difficult as all you would do is
create as many ActionForm instances as you need in your SetupAction and
then put them all into request scope. You then can set up multiple forms
as you see fit on the fowarded to JSP page. 

The only thing I haven't found a nice work around for is that you can
only use one mapping.getAttribute() call in the Action for the form
associated with that Action. In example will help.

You have an Action class that you want to use to prepopulate three
Action Forms and then forward to a JSP page and set up three separate
forms. So you might have a mapping...

action path=/setupMultipleForms
type=foo.bar.SetUpFormsAction
name=form1
scope=request
validate=false

forward
name=continue
path=/severalFormsOnAPage.jsp/
/action

So now in the SetUpFormsAction you can easily put Form1 into scope by:
 
Form1 form1 = (Form1)form;
form1.setFoo(hello);
request.setAttribute(mapping.getAttribute(), form1 );

But now for another ActionForm (Form2) to put into scope you'd have
Form2 form2 = new Form2();
form2.setFooBar(BLA);
request.setAttribute( form2, form2 );

The part I don't like is you now have to remember that you need to
remember that you HAVE to refer to your Form2 object as form2 in your
mapping set up in your struts-config.xml file or else you JSP page will
not be able to find it. It's not a super big deal, but a bit annoying. 
Maybe there is another way to do it that I'm missing.


-- 
Rick Reumann

-
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]



Re: one more prepopulate question

2003-02-28 Thread Rick Reumann
On Fri, 28 Feb 2003 16:01:50 -0500
Sri Sankaran [EMAIL PROTECTED] wrote:
 
   ApplicationConfig appConfig = (ApplicationConfig)
 request.getAttribute(Globals.APPLICATION_KEY);
   ActionConfig actionConfig = appConfig.findActionConfig(/foo);
   String name = actionConfig.getName(); // Form bean name
   String attribute = actionConfig.getAttribute(); // Attribute to
   store under String scope = actionConfig.getScope(); // Scope to
   store in FormBeanConfig fbConfig =
   appConfig.findFormBeanConfig(name);
 
 This is a snippet that Craig wrote up in response to an earlier post. 

That was exactly what I was looking for! Thank you (and Craig of
course:).


-- 
Rick Reumann

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



Re: one more prepopulate question

2003-02-28 Thread Rick Reumann
On Fri, 28 Feb 2003 16:01:50 -0500
Sri Sankaran [EMAIL PROTECTED] wrote:

  action path=/setupMultipleForms
  type=foo.bar.SetUpFormsAction
  name=form1
  scope=request
  validate=false
  
  forward
  name=continue
  path=/severalFormsOnAPage.jsp/
  /action
  
  So now in the SetUpFormsAction you can easily put Form1 into scope
  by:
   
  Form1 form1 = (Form1)form;
  form1.setFoo(hello);
  request.setAttribute(mapping.getAttribute(), form1 );
 
 Actually, unless you are going (back) to a page that contains a form
 with action of setupMultipleForms you can't use this strategy.

What strategy do you mean? The strategy of using
request.setAttribute(mapping.getAttribute(), form1 ); ? I thought that
is the way you 'should' set your ActionForm into request scope in your
Action? Are you saying it should be done a different way?

Thanks,

-- 
Rick Reumann

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



RE: one more prepopulate question

2003-02-28 Thread Zsolt Koppany
Where do I have to insert this code?

Zsolt

 Actually, unless you are going (back) to a page that contains a form with action of 
 setupMultipleForms you can't use this strategy.
 
 What you actually need to know is the name attribute of the action mapping 
 corresponding to the page to which the user is being directed *next*.  However, this 
 isn't the end of the world; you can programmatically figure the name of the 
 form-bean etc as follows:
 
   ApplicationConfig appConfig = (ApplicationConfig)
 request.getAttribute(Globals.APPLICATION_KEY);
   ActionConfig actionConfig = appConfig.findActionConfig(/foo);
   String name = actionConfig.getName(); // Form bean name
   String attribute = actionConfig.getAttribute(); // Attribute to store under
   String scope = actionConfig.getScope(); // Scope to store in
   FormBeanConfig fbConfig = appConfig.findFormBeanConfig(name);
 
 Now you've got all the metadata you need to dynamically instantiate the
 appropriate form bean, and store it under the appropriate attribute in the
 appropriate scope, without hard coding any of this stuff.
 
 This is a snippet that Craig wrote up in response to an earlier post. 
 
 
 Sri
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
-- 
Zsolt


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



one more prepopulate question

2003-02-27 Thread Dan Allen
I know that the prepopulate question has been beaten into the ground
around here and the answer on the FAQ page is complete in answering
most questions I have about the concept.  But I just want to run
something by this list, see if I am going about it in the right way.

When you are designing an application, and the index page has
several mini-forms (such as a limited search, a login and maybe a
site index) the first page has to be a *.do page.  So I figured,
make an index.jsp page with

logic:redirect page=/index.do/

Then my /index action would prepare the forms and display /home.jsp.
The FAQ talks about putting the form population in the Action class
for the /index action, which works great...

...except, how would you populate more than one form?  Seems like in
the cast you limit yourself to the form defined in the action
mapping.  Would it be necessary to just set up an action chain?

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, [EMAIL PROTECTED]
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Real programmers just hate to get up in the morning, and 
contrary to Ordinary People, they're in better shape as 
it gets closer to nighttime.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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



Re: one more prepopulate question

2003-02-27 Thread Rick Reumann
On Wed, Feb 26,'03 (06:51 PM GMT-0600), Dan wrote: 

 I know that the prepopulate question has been beaten into the ground
 around here and the answer on the FAQ page is complete in answering
 most questions I have about the concept.  But I just want to run
 something by this list, see if I am going about it in the right way.
 
 When you are designing an application, and the index page has
 several mini-forms (such as a limited search, a login and maybe a
 site index) the first page has to be a *.do page.  So I figured,
 make an index.jsp page with
 
 logic:redirect page=/index.do/
 
 Then my /index action would prepare the forms and display /home.jsp.
 The FAQ talks about putting the form population in the Action class
 for the /index action, which works great...
 
 ...except, how would you populate more than one form?  Seems like in
 the cast you limit yourself to the form defined in the action
 mapping.  Would it be necessary to just set up an action chain?

I'm curious how you would accomplish this as well.

-- 
Rick

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