aspose file tools*
The moose likes Struts and the fly likes read dynamic text fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "read dynamic text fields" Watch "read dynamic text fields" New topic
Author

read dynamic text fields

robbie keane
Ranch Hand

Joined: Sep 05, 2005
Posts: 54
Hi,
In my project I'm using struts. I have a requirement that in my jsp page, I need to create a link by clicking which few text boxes will be generated. So if I click this link say 5 times, it should give 5 set of text boxes. Now I need to read these text fields in my Action class. Now how do I define these dynamic fields my form class (some array, list etc) and use them in action?

regards
Robbie
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
Read about indexed properties. It allows you to populate a list in your action form. Then, you can create the input type=text boxes using javascript and if you give them the correct name the form will be populated correctly.
[ February 26, 2007: Message edited by: Dom Lassy ]
Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
You can use dynaaction form with indexed string arrays a properties and define the incremental counter at class level so that it gets incremented on each click and you need to reset it before returning from execute method of your action class


SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
robbie keane
Ranch Hand

Joined: Sep 05, 2005
Posts: 54
Thanks. I tried indexed properties.
I used the foll code but if i try reading the form fields in next action, i get null value.

my form snippet looks like:
public String[] getAddressTelephone() {
return addressTelephone;
}

public void setAddressTelephone(String[] addressTelephone) {
System.out.println("#####addressTelephone###");
this.addressTelephone = addressTelephone;
}

my jsp has:
<c:forEach var="addcity" items="${editProfileForm.addressCity}">
<tr>
<td valign="middle"><strong><font color="ff0000">*</font> City: </strong></td>
<td valign="middle">
<html:text property="addressCity" name="editProfileForm" value="${addcity}"/>
</td>
</tr>

<BR/>
</c:forEach>

and in my action:
String[] addCity =
editProfileForm.getAddressCity();
if(addCity!=null){
for(int i=0;i<addCity.length;i++){
System.out.println("####$$$$$addCity\n" +
addCity[i]);
}
}
This addCity is always null.


VIEW source of html looks like:
<tr>
<td valign="middle"><strong><font color="ff0000">*</font> City: </strong></td>
<td valign="middle">
<input type="text" name="org.apache.struts.taglib.html.BEAN[0].addressCity" value="abcdZZ">
</td>
</tr>

pls help.

Thanks in anticipation.
Robbie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: read dynamic text fields