This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot pass checkbox array to Java bean

 
Jerry Goldsmith
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good afternoon,

I am attempting to pass a checkbox array from a jsp page to a java bean with no luck. I am setting properties in the bean using the name property of the input tag. I realize this would be easier with Struts 2 or a similar framework but I am under serious time constraints with no time to spare learning a new framework.

It may be that the checkbox does not conform to an array type of Object or that I'm naming the input tag improperly. The initViewDVO() method is called from an earlier jsp page. Would someone be so kind as to peruse the following code snippets and, perhaps, provide me with a tip or two? Thank you.

Here is my bean:



The array is initialized here:



Here is the relevant jsp:

 
John Gregory
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jerry,

I know that if a group of check boxes is returned in a String []. When I use them in
a form, in my server/jsp code I do something like:



Then to iterate through:



Hope this helps.

John
 
Jerry Goldsmith
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,

Thank you for your reply. I changed my check box array to a type of String[] rather than Object[] however I still don't get the result I want. I am testing my result by displaying the first element of the array on my web page like so:



The initial value is displayed correctly but does not update when the form is submitted. I have also tried getting the check box using the request parameter you mentioned:



This results in a null pointer exception at the out.print... line.

Thanks again for taking the time to help. I will post when I figure this one out. I'm sure I am missing something simple.
 
Sunil Vasudevan
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jerry Goldsmith wrote:


Jerry Goldsmith wrote:


In your JSP, you are having a different name for your checkbox and in getParameterValue() you are using a different name.

 
Jerry Goldsmith
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks John. Thanks Sunil.

Actually, the array name in the input tag and the request statement did match. That was just a typo.

I found the real issue. A checkbox array will return null, if nothing is checked, in which case you need to catch the null Pointer Exception. If it is checked, the array element will contain the value from the corresponding input tag. In my case that would be my iterator "i".

Thanks again.

Cheers!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic