Pregunta

I need to disable few items in selectItem list based on a backing bean. Below is the code snippet

<h:selectOneMenu required="#{bean.tbiLotNumberRequired}" 
    label="TBI Lot # " id="tbiLotNumber" 
        value="#{bean.unitDTO.tbiLotNumber}" 
            disabled="#{bean.disableLotSpecificFields}">
    <f:selectItem itemLabel="-Select-" itemValue =""/>
    <f:selectItems value="#{bean.communityLotNumber}"/>
</h:selectOneMenu>

The value of selectItem is backed by MyFaces SelectItem.

Now, the bean I'm setting the "disabled" property of SelectItem thru setDisabled in my backing bean. It does not work.

Alternatively, I tried both below options

<f:selectItems value="#{bean.communityLotNumber}" var="lot"
                   itemDisabled="${lot.isDisabled}"/>

and

<f:selectItems value="#{bean.communityLotNumber}" var="lot"
                   itemDisabled="${bean.isDisabledLot(lot)}"/>

with a backing bean to evaluate the SelectItem and return the boolean value to set it true. But, probably since im using JSF 1.2, the server throws the below error

com.sun.facelets.tag.TagAttributeException: /WEB-INF/flow/xx/xxxxx/xxcreate_a.xhtml @109,122 itemDisabled="#{bean.isDisabledLot(lot)}" Error Parsing: #{bean.isDisabledLot(lot)}
at com.sun.facelets.tag.TagAttribute.getValueExpression(TagAttribute.java:259)
at com.sun.facelets.tag.jsf.ComponentRule$ValueExpressionMetadata.applyMetadata(ComponentRule.java:69)
at com.sun.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:36)
at com.sun.facelets.tag.MetaTagHandler.setAttributes(MetaTagHandler.java:62)
at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:144)
at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)

We are using MyFaces1.2, JSF 1.2 and RichFaces 3.3

can someone suggest an alternative.

¿Fue útil?

Solución

The above must work withe the exception that the var, values and itemDisabled properties' do not have the same backing bean. That is wrong. The variable and the values must correlate.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top