Easy Select Items for JSF

In order to use selection components like combos or listboxes, SelectItem objects are needed in JSF. There are two tags for the job in the spec. f:selectItem and f:selectItems. The singular one has itemLabel and itemValue attributes which also accepts value bindings other than static texts. The main problem is with the f:selectItems because it only gets a value attribute and does not have the itemLabel-itemValue attributes. This causes two problems.

* To display a collection in a page, you have to create a SelectItem collection from your data. Suppose you have a collection of customer objects and want to display the name-surname attributes as key-value in a combobox. The bad thing is that you need to iterate over the collection and create a new collection of SelectItem objects and return it to the component.
* By doing so, the domain model is coupled with the faces api.

Because of these two disadvantages, me and my buddy Mert created an extended version: s:selectItems. It has three new attributes; var, itemLabel and itemValue. By using this, the component automatically creates the Select Items collection from the given data. I dont think many people care about ibm’s jsf but it has a custom resolver to create the selectitems. Anyway I’ve deployed the example webapplication to my homepage at;

www.cagataycivici.com/easysi

The component is also committed to Apache MyFaces Sandbox project by Martin and I believe it’s going to be promoted to tomahawk soon. Also an interesting thing occurred the day component joined sandbox, a user in myfaces list send a message saying the selectitems stuff is problematic in JSF, creating them takes time&effort and asked if an easier way exists in myfaces. Of course he is pointed to our new component in sandbox afterwards, seems the component joined at the right time. If you are not a myfaces user and want to use it anyway, check out the release at jsf-comp. I’ve also written a documentation there.

7 Responses to Easy Select Items for JSF

  1. _rogerio_ says:

    Yeah, when i saw this tag there i changed some projects here to use and now the things are much simplier.

    But you made a reference in this blog entry as s:selectItems but i could only use as s:selectitem, i think this isn’t the correct naming rule.

    Nice work validator man!

  2. Cagatay says:

    Hi Rogerio, yeah Martin is gonna fix the letter problem. I wonder how I missed it:)

  3. Pingback: Creating JSF SelectItem : Martin Ahrer

  4. wachovia says:

    I have considerably improved my credit score recently and have been elevated for FICO B rating. However, for Transunion and Experian, they are now using Vantage instead, which lowers me to a C cat. Do you know which scoring system do they use at

    0 percent apr lifetime transfer discover

  5. said says:

    Thk for this solution good idea and more pratical for me.
    but i have the problem if u can i xould like to help me.
    my tag page jsf is

    ##########################”
    users : is a collection of object (User)
    ##############################”

    but the result of html page is :

    thx

  6. said says:

    sorry for my post
    pleas i think that i have a confusion of library:
    ajax4jsf-1.1.1.jar
    commons-beanutils-1.7.0.jar
    commons-codec-1.3.jar
    commons-collections-3.2.jar
    commons-digester-1.8.jar
    commons-discovery-0.4.jar
    commons-fileupload.jar
    commons-io.jar
    commons-logging-1.1.jar
    el-api.jar
    el-ri.jar
    gravel-14.jar
    javassist.jar
    jboss-retro-1.1.0-rt.jar
    jbpm-identity.jar
    jbpm-jpdl.jar
    jbpm4jsf-14.jar
    jsf-api-14.jar
    jsf-facelets.jar
    jsf-impl-14.jar
    jstl.jar
    standard.jar
    tomahawk-1.1.6.jar
    EasySI-0.9.0.jar
    tomahawk-facelets-1.1.6.jar

    in the page the select give me no selectietm.
    in the HTML source of page it give me s:selectitems and it sn t convert to selectitem
    thk you for your help

  7. Pingback: Cracks House

%d bloggers like this: