Question

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>
Was it helpful?

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...

OTHER TIPS

This is a classic example of non-DRY code, which is bad. Daniel shows perfectly how to make it DRY, however he didn't explain the cause of your problem.

Based on the problem symptoms, this will happen when #{projectBean} is a view scoped bean. View scoped beans are stored in the JSF view state. So, view scoped beans are only available after restore view phase. However, JSTL tags runs during restore view phase, while the view scoped beans are not available yet. This causes creation of a brand new view scoped bean instance, which is then later replaced by the real view scoped bean which was stored in the restored JSF view state. The brand new and separate view scoped bean which is used by JSTL will have all its properties set to default and thus the block which has updateFlag=false will always be invoked.

See also:

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