• 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

how to create property,setter getter for TextBox field whose name would be dynamically created?

 
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Struts 2 Form from which I am entering fields including Email IDs.Now user can have click on add to dynamically add new text box for entering more email Ids. So the names of textboxes in such a case would be created on user click of add more button. But the problem is that field names in Struts 2 have to be properties of Action class with setter getter methods. But how can i create property and setter getter for a textbox whose name is not yet known. ? Suppose there are 5 fields as text box and I have 5 properties in action class with setter getter.Now I click add button and dynamically generate a new text box for additional emailId.How can i have this name as property of action class when this name is known only dynamically on click of add button?

thanks
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use an indexed property (yes, that page is for Struts 1.x, but the principal applies in Struts 2.x). Basically the getter/setter on your action or data object should take a collection and the name of your text box should be the collection name plus an index.
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.Apart from that I read one more post:
webpage

In this I saw the idea that create dynamic text box create them as textBox1,textBox2 and so on and use the same name in FormBean( in Action Class only in struts 2).


I tried the below:




Idea is to use same name in Action Class property.
The above works but below does not:





Now I would use the name EmailId1 as property but the above does not work.Please advice.

Thanks.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you looking at this example? Notice that your code does not look like the code in the example.
You also haven't shown your action. I assume your getter and setter takes a collection.
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I've same requirement now. I've a bundle of text boxes in one <li><table><tr>1</tr><tr>2</tr><tr>3</tr><tr>...</tr></table></li>. So, when I click on add button, it produces another <li><table>bundle of text inputs</table></li>. My problem is, how to create dynamic setters and getters for all inputs. here is my all source code. Please guide me or modify the code, the way it has to be.

Action.class



Struts.xml


index.jsp



collection class:



bean class



DBstore class.




Please reply as soon as possible


Thanks:
Ramakrishna K.C
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ramakrishna Udupa wrote:
Please reply as soon as possible



Please do not post the same question more than once. I've already linked to a relevant example in your other post. Since you found Monica's post you can obviously search the forum for other examples, of which there are many. We will not do your work for you. If you show some effort we would be glad to help you.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic