Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getting an array into a bean  RSS feed

 
Richard Adams
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,,
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
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!