*
The moose likes Struts and the fly likes prepopulating html forms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "prepopulating html forms" Watch "prepopulating html forms" New topic
Author

prepopulating html forms

Graham VMead
Ranch Hand

Joined: Sep 22, 2003
Posts: 154
Hi

I'm fairly new to struts and wonder if someone could set me straight on a couple of points.

1) Is it considered bad practice to share ActionForms across requests, at session scope, i.e same action form for screen1 to 2 to 3 but using different attributes of the form.

2) On a similar note, what is the usual way of prepopulating an html form's fields. I've seen examples where an Action populates a bean, stores it in request scope and then the subsequent jsp is coded via usebean: to populate its fields from this bean.

If the actionform was shared across actions, couldn't this be used as the bean to populate subsequent form fields via usebean:myForm, or does this introduce too much inter-screen dependency?

It just seems to me that ActionForms are a bit unidirectional, user keys some stuff in, ActionForm is populated from request, but not the other way round, html form fields populated from ActionForm(via jsp usebean).

Thanks to anyone who replies

Graham
Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
You can prepopulate the ActionForm in the Action classes execute method.

I don't think it would be considered bad design to use the same form on multiple actions, as long as they are related.


http://www.goodercode.com
SCJP 1.4
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Originally posted by Graham VMead:
It just seems to me that ActionForms are a bit unidirectional, user keys some stuff in, ActionForm is populated from request, but not the other way round, html form fields populated from ActionForm(via jsp usebean).


I don't know where you got the jsp usebean idea, but Struts will automatically populate the fields with the values from the corresponding ActionForm.


A good workman is known by his tools.
Graham VMead
Ranch Hand

Joined: Sep 22, 2003
Posts: 154
I don't know where you got the jsp usebean idea, but Struts will automatically populate the fields with the values from the corresponding ActionForm.


Ahh well this maybe where my understanding falls off the edge.

Let me rephrase it.

1) I bring up screen 1 which has a field "Address" on it
2) User enters his address presses submit
3) The submit path maps to an action with an asscoiated form AddressForm
4) Struts automatically populates the form from the request via setAddress()
5) The associated action does its stuff and ultimately returns an ActionForward
6) This ActionForward maps directly to a second jsp screen 2
7) This jsp needs to show the Address data from screen1

How does struts automatically populate the fields unless I link in the AddressForm somehow??

Do I specify the AddressForm as session scope and what should 6) map to?
another action with AddressForm specified as well?
Fallen Angel
Greenhorn

Joined: Sep 07, 2005
Posts: 5
This is what i did.

1.
In your jsp(tile) open a html:form tag then nest a html:select then nest a logic:iterate (passing your recordset bean to its id parameter).

2.
Inside the logic:iterate open a html ption tag passing its value parameter a jsp scriplet <%=yourbean.getProperty()%> - this is useful for setting id's for further searching.

3.
Inside the html ption nest a bean:write pasiing the name of the bean property you wish to output to its 'property' parameter.

4. close html ption, close logic:iterate, close html:select tags.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: prepopulating html forms
 
Similar Threads
Regarding Form and
Prepopulating a jsp form before submitting - using Struts?
Prepopulating a form
Prepopulating Radio buttons in JSP
Prepopulating a DynaActionForm