File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes JSF 2.0 and Checkbox layout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF 2.0 and Checkbox layout" Watch "JSF 2.0 and Checkbox layout" New topic

JSF 2.0 and Checkbox layout

Mike Laris

Joined: Oct 26, 2009
Posts: 6

I am attempting to create a set of checkboxes using <h:selectManyCheckbox>. The checkboxes are being generated from a database table and there are 20 to 30, but the only layout is everything in one row, or one column. I have searched this forum, and the internet in general, and the question has been asked several times. The best answer seems to be to use Tomahawk, but according to other threads in this forum, Tomahawk has issues with JSF 2.0 (I am using the Sun RI). Other solution are to write a custom renderer, or a custom UI component. That seems like an enormous amount of work (especially for someone who is still learning the basics of JSF) for something that should be incredibly simple. Am I missing something? Some simple JSF technique that will make this work? I have been very impressed with JSF 2.0 until this point.

I cannot believe that I am the only person to have had this problem. Can anyone point me to a good solution? I am about ready to roll up my sleeves and write a custom UIComponent. Something like SimpleCheckbox. All that it will need to output is:

<span><input type="checkbox" name=.... /><label ... /></span>

and then I can use a <h:panelGrid> for layout. Of course, it should do everything that the <h:selectManyCheckbox> already does. Can some of you more experienced JSF programmers tell me if this sounds like the proper solution? Or am I over-engineering a solution? I would prefer an already packaged solution, since my job is to write a website, not write UI Components.

Any advise will be appreciated.

Mike Laris
Mike Laris

Joined: Oct 26, 2009
Posts: 6

Well, I have come up with a solution. I do not particularly like it, but it does seem to work. Once again, for you more experiences JSF programmers, please tell me if there is a better solution. What I have done is to break the checkboxes into two group and use two separate <h:selectManyCheckbox> tags. The HTML is as follows:

From the backing bean, I wrote the following code:

This is a bit complicated for setup, but does work. Is there a better solution available now? I suspect long-term I will use Tomahawk when it is stable with JSF 2.0.

I agree. Here's the link:
subject: JSF 2.0 and Checkbox layout
It's not a secret anymore!