| Author |
Difficulty Using checkboxes in JSF
|
Janardan Kelkar
Ranch Hand
Joined: May 05, 2008
Posts: 69
|
|
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??!!
|
When the compiler's not happy, ain't nobody happy.
|
 |
Srini Mutpur
Greenhorn
Joined: Mar 29, 2008
Posts: 24
|
|
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
|
SCJP 1.5
|
 |
Janardan Kelkar
Ranch Hand
Joined: May 05, 2008
Posts: 69
|
|
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
Joined: Jun 14, 2009
Posts: 45
|
|
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
Joined: May 05, 2008
Posts: 69
|
|
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
Joined: May 05, 2008
Posts: 69
|
|
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
Joined: Jun 14, 2009
Posts: 45
|
|
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
|
 |
 |
|
|
subject: Difficulty Using checkboxes in JSF
|
|
|