aspose file tools*
The moose likes Struts and the fly likes form field population done right Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "form field population done right" Watch "form field population done right" New topic
Author

form field population done right

Pranav Sharma
Ranch Hand

Joined: Oct 27, 2003
Posts: 257
I'am populating a form by getting data from the database.
In the action I instantiate myform, set form data and call return forward as following.
ACTION 1


in the JSP i have



But the form is not populated. Now if I put the form in session scope

request.getSession().setAttribute("data",myForm);

and in the jsp call
<html:text name="data" property="data1">

this works but I dont want to add my forms to session scope because I have many and also I think this also gives me the following problem when I hit my "next" link the form that i get in the action is empty.

thanks
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

The execute method of your Action has an ActionForm parameter for a reason. It is not necessary to instantiate forms. Define your form for the ActionMapping in your struts-config. Using this method, and if you use the html:form tag, the name attribute of your html: tags is no longer necessary. This will prevent a lot of confusing errors like the one you're having.


A good workman is known by his tools.
Pranav Sharma
Ranch Hand

Joined: Oct 27, 2003
Posts: 257
Thanks Marc. I still have a doubt on this,
The ActionForm in the Action is from the previous page(right?), and if I'am trying to set values for a form on the next jsp, would I not have to do the above to populate. (if not could you point me in the right direction with a general outline of what you have said above in terms of dummy code)

also i find that the next action gets an empty actionform because i'am using <a href="ViewData4.do?dispatch=prev&page=dis1"> link.
Maybe I will have to use a submit button, or can I use <html:link> to achieve the above
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: form field population done right
 
Similar Threads
data stored in DynaActionForm is not displayed on jsp page
Form Params not passed properly
Retrieving prepopulated form values in jsp
form values not set correctly
Duplicate form submission - Synchronizer Token Pattern