This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes Regarding form property as array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Regarding form property as array" Watch "Regarding form property as array" New topic
Author

Regarding form property as array

krish chaitu
Ranch Hand

Joined: Oct 09, 2007
Posts: 32
Hi,

I have some basic question like
can i have a form bean having setters & getters for a firstname textfield on the screen with each text field has different property name for example like
first text box will have firstname ,second will have firstname1 etc for 10 text boxes & i want all this to be in array
can i define something like
public void setFirstName(String[] firstName){}

public String[] getFirstName(){}

Please help in this problem,

i need to figure out how i can make this working

Thanks
krish
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If they all have the same name, you can retrieve them as an array with request.getPropertyValues.

See:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletRequest.html


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
krish chaitu
Ranch Hand

Joined: Oct 09, 2007
Posts: 32
hi,

my problem is with the user entry .so i have in my entry screen for user to enter contact information & i have 5 contact informations for the user to enter ,so instead of having 15 first name setters & getters properties , i want to find some easiest solution to make the form bean not to have too many setters & getters.

so can i know how i can make the form bean proeprty to have all this 15 firstnames with one setter & getter methods.

Please help me out in this issue, iam already in big trouble to sort it.


Thanks
krish
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Consider representing this as a list of beans.
 
Consider Paul's rocket mass heater.
 
subject: Regarding form property as array