File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "form field population done right" Watch "form field population done right" New topic

form field population done right

Pranav Sharma
Ranch Hand

Joined: Oct 27, 2003
Posts: 258
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.

in the JSP i have

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


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.

Marc Peabody
pie sneak

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: 258
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=""> 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:
subject: form field population done right
It's not a secret anymore!