Question

I've noted a strange behaviour of the Primefaces 3.5 application that I'm currently writing. I was debugging my code code and it turned out that when I'm using a jsf component and try to pass a listener like this

           <form:dictionarySelectInput id="country"
                                        name="country"
                                        label="label.claim.BelongingsSecondPage.property.country"
                                        filter="true"
                                        value="#{belongingsDataGatheringBean.page.belongingsSection.propertyBelonging.country}"
                                        items="#{belongingsDataGatheringBean.dictionaries.countryDictionary()}"
                                        listener="#{belongingsDataGatheringBean.changeCountryListener()}"
                                        update="@([id$=state\\:state-panel])"/>

then during rendering the view the method is called by itself. Here's how the component uses the listener:

    <p:selectOneMenu id="#{cc.attrs.name}-input" value="#{cc.attrs.value}" styleClass="select #{cc.attrs.styleClass}" filter="#{cc.attrs.filter}" converter="omnifaces.SelectItemsConverter">
        <f:selectItem itemLabel="#{msg['common.select.empty']}" noSelectionOption="true"/>
        <f:selectItems value="#{cc.attrs.items}" var="item" itemLabel="#{item.value}" itemValue="#{item}"/>
        <c:choose>
            <c:when test="${empty cc.attrs.listener}">
                <p:ajax disabled="#{empty cc.attrs.update}" process="@this" listener="#{cc.attrs.listener}" update="#{cc.attrs.update}"/>
            </c:when>
            <c:otherwise>
                <p:ajax disabled="#{empty cc.attrs.update}" process="@this" update="#{cc.attrs.update}"/>
            </c:otherwise>
        </c:choose>
    </p:selectOneMenu>

How to prevent the listener from firing itself?

Was it helpful?

Solution

This is not right:

<c:when test="${empty cc.attrs.listener}">

The #{cc.attrs.listener} is here evaluated as a ValueExpression in order to satisfy the empty check. Thus, the entire EL expression is executed as if it's a property and the (getter) method behind the EL is invoked and its result is returned to the empty check.

You need to check it as follows instead:

<c:when test="#{cc.getValueExpression('listener') != null}">

This won't execute the EL expression, but just check if there's a ValueExpression present without actually evaluating it.

See also:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top