Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

read dynamic text fields

 
robbie keane
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
robbie keane
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic