• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

read dynamic text fields

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic