• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

getting an array into a bean

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,,
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Do Re Mi Fa So La Tiny Ad
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic