Search code examples
jsf-2primefacesjstlactionlistenerfacescontext

actionListener not called inside <c:if>


I have the following code, Using jsf2.2, primefaces 3.2. My requirement is to update the Project depending on the updateFlag. when i use c:if (xmlns:c="http://java.sun.com/jsp/jstl/core") like the following code the action Listener for the Update commandButton is not called. but if i use < p:panel rendered="#{projectBean.updateFlag}" > instead of < c:if > it works. Please help i dint get it, i think i should use c:if but its not working.

<p:dialog widgetVar="projectUpdate" id="projectUpdatePanel" modal="false" >

                <p:panel>
                    <c:if test="#{projectBean.updateFlag == false}">
                            <h:outputText value="Project Title" />
                            <p:inputText disabled="true" value="#{projectBean.selectedProjectDo.projectTitle}" />
                            <p:commandButton value="Update" disabled="true" />
                            <p:commandButton value="Cancel" actionListener="#{projectBean.cancelUpdate}" />
                    </c:if>
                    <c:if test="#{projectBean.updateFlag == true}">                           
                            <h:outputText value="Project Title"/>
                            <p:inputText value="#{projectBean.selectedProjectDo.projectTitle}" />
                            <p:commandButton value="Update" actionListener="#{projectBean.updateProject}" />
                            <p:commandButton value="Cancel" actionListener="#{projectBean.cancelUpdate}" />
                    </c:if>
                </p:panel>

            </p:dialog>

Solution

  • You better just use it the following way (put a condition on the disabled attribute)

    <p:panel>                     
        <h:outputText value="Project Title"/>
        <p:inputText disabled="#{not projectBean.updateFlag}" 
            value="#{projectBean.selectedProjectDo.projectTitle}" />
        <p:commandButton disabled="#{not projectBean.updateFlag}" value="Update" 
            actionListener="#{projectBean.updateProject}" />
        <p:commandButton value="Cancel" actionListener="#{projectBean.cancelUpdate}" />
    </p:panel>
    

    In general : don't use JSTL tags unless you really need them...