Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

getting an array into a bean  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am learning how to use beans with jsp.
As I understand it String values from request parametere can be automatically put into data fields using "property="*" in the jsp:setProprty tag. This is all very well, but what if you have a checkbox in your form which takes multiple selections?
To get the values you would need to call getParameterValues(fieldname)which would return a String array, which could not go in a bean.

Are there any solutions to this? It seems a bit odd that simple fields can be assigned but as I understand it would you need a scriptlet to put the array into the bean???

Many thanks, sorry if this is too obvious,,
 
Author and ninkuma
Marshal
Posts: 66810
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Richard, welcome to the Ranch.

but what if you have a checkbox in your form which takes multiple selections?



For a property that can posess multiple values, you need to be sure to set up the property in the JavaBean as an indexed property. Details on which accessors and mutators are necessary can be found here.

Once the bean is set up correctly for the indexed property, the multiple values get correctly added to the bean as an array.

P.S. This sort of thing is only necessary when you are submitting a form directly to a JSP. This structure for a web application is considered passe by today's conventional wisdom. In fact, the newly published March issue of the JavaRanch Journal has an article I wrote that discusses web application structures that you may find interesting.
 
Richard Adams
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks for the informative reply!
I'm learning from the HeadFirst JSP book which is generally excellent but
rather glossed over this point.
Cheers
Richard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!