Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Form and

 
Chetan Pandey
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
type="com.BLUE.lms.actions.EditAttendeeDetailsAction"
name="EditAttendeeDetailsForm"
scope="request"
validate="true"
input="/editAttendeeDetails" >
</action>

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.

Example:

Name: John
SSNL 222-22-2222

where the folloing code is being used:

<table>

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

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

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

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

FORMBEAN_AUTOMATICALLY_ASSOCIATED_WITH_THIS_JSP_PAGE = formbeanInstance_1

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

(1) "FORMBEAN_AUTOMATICALLY_ASSOCIATED_WITH_THIS_JSP_PAGE"
(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,

Chetan
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
type="com.BLUE.lms.actions.PopulateAttendeeDetailsAction"
name="EditAttendeeDetailsForm"
scope="request"
validate="false" >
<forward name="success" path="/editAttendeeDetails.jsp" />
</action>

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



When you want to display the EditAttendeeDetails JSP, enter:

http://myserver.com/myApp/populateAttendeeDetailsAction.do

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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic