• 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

Creating dynamic text boxes in Struts 1

 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,

I want to create dynamically text boxes in a Struts form and want to map those text box field into a form bean , So that i can read back those value in action class, Now my problem is I am not sure how many Text box variable i need to declare in my Form Bean class ?

Any help or suggestion is greatly appreciated .

Thanks in advance .
 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One approach you can adopt is that you give all your textboxes the same value for the name attribute. And have getter/setter for the same name in your form bean. Just remember that instead of handling a String value, your getter/setter should handle a String[].
Something like:

This way you don't need to be concerned about how many textboxes are rendered. Be it a single or "n" number of textboxes, the values for each of them will get saved into the String[] of the form bean.
However, you'll need to put in some additional logic either at the client or server side, if it is important for you to map values present at different indices of the String[] to particular labels. Things you need to keep in mind:
1. If the user doesn't enter any value in any one of the textboxes, then there will not be a blank entry corresponding to it in the form bean's String[] variable.
2. The order in which the values are present in the String[] is directly related to the order in which the textboxes appear at the client side.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Anirvan

Its woking for me !!

Thanks again ..
 
You got style baby! More than this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic