Search code examples
cssjsf-2liferaycustom-componentrenderer

attribute on selectonemenu jsf


I have a little trouble with tag h:selectOneMenu, I just want to add some background image to option, such as avatar of user.

Follow styling options in h:selectOneMenu - by balusC

I had tried to render options with its own style css.

<h:selectOneMenu id="dropListUser"
        value="#{myController.myUserObject.userid}">
    <f:attribute name="avatar" value="#{true}"></f:attribute>                           
    <f:attribute name="key" value="somthing"></f:attribute>
    <f:attribute name="height" value="32"></f:attribute>
    <f:attribute name="width" value="32"></f:attribute>
    <f:selectItems value="#{myController.listOfUsers}" var="item" itemLabel="#{item.username}" itemValue="#{item.userid}"/>
</h:selectOneMenu>

It work great with height, width and key, but with avatar(or any attribute contains value with #{} expression) server bean could not get it.

Try to printout all key name:

Iterator itr = component.getAttributes().keySet().iterator();
        while(itr.hasNext()){
            System.out.println(itr.next().toString());
        }

there is no key with name avatar :

--------------------------------
height
javax.faces.component.VIEW_LOCATION_KEY
com.sun.faces.facelets.MARK_ID
key
width
width: 32 height: 32 style null?: true
--------------------------------

ps: by the way,Is there any one know how to create custom taglib that extends h:selectOneMenu :-?

ps2: In the fact, If I could get myController.listOfUsers in <f:selectItems value="#{myController.listOfUsers}" var="item" itemLabel="#{item.username}" itemValue="#{item.userid}"/> in my custom render bean, it could be better


Solution

  • Woof, I don't know why or how, but when try print out all of key names from component.getAttributes() also component.getAttributes().containsKey("avatar") return that avatar is not exist, BUT I really can get avatar value, my trouble was solved ^^" just remove code that check the key exist or not