File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Regarding Form and Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Regarding Form and " Watch "Regarding Form and " New topic

Regarding Form and

Chetan Pandey
Ranch Hand

Joined: Aug 01, 2005
Posts: 31
I have a JSP class "editAttendeeDetails.jsp" in Struts Framework.

An ActionForm is associated with this JSP class in the given action-mapping from struts-config.xml

<action path="/editAttendeeDetailsAction"
input="/editAttendeeDetails" >

The following is what I want to do.

(1) I want to print a table of the fields of my FormBean("EditAttendeeDetailsForm")
with the field name as label and its corresponing value inside the Textfield.


Name: John
SSNL 222-22-2222

where the folloing code is being used:


<td>First Name:</td>
<td><html:text property="attendeeVO.firstName" /></td>

<td> SSN: </td>
<td><html:text property="attendeeVO.lastName" /></td>

<td><html:submit/> <html:reset/></td>

But my problem is that if I say value="something" this will only take a literal so I cant dynamically poplate it.

I am told that if the formbean is non-null it will dynamically take the corresponind value.

But my problem is how to insert values into this formbean's fields as I cant find it in either request or page scope.

How can I say


I have "formbeanInstance_1" but I dont know how to retrieve

(2) to set it to "formbeanInstance_1"

Plese tell me how can I get a reference to the formbean and how to set it.

Most gratefully,

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you want to pre-populate the fields in a form, here is what you need to do:

1-Create an action similar to the following:

<action path="/populateAttendeeDetailsAction"
validate="false" >
<forward name="success" path="/editAttendeeDetails.jsp" />

2-In the execute() method of this Action class put code something like this:

When you want to display the EditAttendeeDetails JSP, enter:

When you do this, Struts instantiates the EditAttendeeDetailsForm bean and puts it in request scope. You then call setters on the ActionForm to populate the properties. When Struts forwards to the JSP, the form will be populated with the values in the AttendeeVo object. That is part of the function of the <html:text> tag: It calls the getter to populate the text box with data from the ActionForm bean.

Does this make sense now?

Consultant, Sima Solutions
I agree. Here's the link:
subject: Regarding Form and
It's not a secret anymore!