This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Difficulty Using checkboxes in JSF  RSS feed

 
Janardan Kelkar
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I am new to JSF. I have a problem using checkboxes, using the 'SelectManyCheckboxes' tag.


In the above code, myList is an ArrayList of type SelectItem (which has been populated properly in the bean) , and 'myOtherList' is a String array. Now i am having several issues here,
i] the checkboxes are not displayed properly, that is instead of getting something like

i am getting this,

How do i get rid of this? is there any way abt this using JSF strictly?

ii] Am also confused regarding how to take the selected checkboxes back to the bean, i have used a String array to hold that data. IS this right in the first place??!!
 
Srini Mutpur
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

1. I think you are facing checkbox and label alignment issue. The h:selectManyCheckBox will be converted to html table. Just check your css and adjust it properly for the alignment.
And also h:selectManyCheckBox has the properties like pageDirection, lineDirection, LTR etc. as per your requirement.

2. Yes, we need to use the String array has to value binded for h:selectManyCheckBox.

Thanks
Srini
 
Janardan Kelkar
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not using any CSS currently...and i cannot understand how to use it in this case, to resolve my issue....

Also, i am getting an IllegalArgumentException for the binding attribute..i am using a string array which i have defined in the bean, and provided getters and setters for it... !!
 
Radu Mircea
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

You could try to do it without h:selectManyCheckBox, may be you could have a c :forEach instruction and inside it a h:selectCheckBox to generate the same output and solve most of the issues related to h:selectManyCheckBox , but i guess that you will need to change business logic.

Hope this helps.

Radu
 
Janardan Kelkar
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

yes, i changed the jsp code to this:



Now, the page is rendered properly, but am now confused about taking this information back to the bean. After selecting a couple of items on the page, i wrote a sample method in the bean, as follows:


This just prints out the default toString() version of the 'value' object of SelectItem. Should'nt 'value' be boolean or something??
How do i get over this?
Thanks
 
Janardan Kelkar
Ranch Hand
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok sorry, i got the problem, i am trying to store the value of a checkbox in a selectItem object!!!
so careless of me...

Is there a way to somehow relate the boolean value of checkbox with the value object of selectItem in the bean??
 
Radu Mircea
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope that i understood right your post.

Supposing that item.value , from your check box is a Boolean value you should iterate through "myList" collection and ask "for each" object (item) if the item.value is true, if so you can get the string label or something like that.

Are you also using Spring ?

Regards,
Radu
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!