0

I have a code like this:

<p:outputPanel id="conditionalPanel">
    <p:panel rendered="#{object.category.string == 'foo'}">
        <ui:param name="foo" value="#{object}"/>
        <h:panelGrid columns="3" id="fooAssignmentsuttonGrid">
            <h:outputLabel for="barToAdd" styleClass="desc" value="#{foobarzooUIData.label}"/>
            <h:selectOneMenu id="barToAdd" value="#{fooController.barToAdd}">
                <f:selectItems value="#{barsToAddAssignments}"
                               var="foobarzoo" itemValue="#{foobarzoo}" 
                               itemLabel="#{foobarzooUIData.buildLabelForObject(foobarzoo)}"/>
            </h:selectOneMenu>
            <p:commandButton value="#{text['button.add']}" process="@this barToAdd" 
                             update="assignmentDetail" disabled="#{empty barsToAddAssignments}"
                    action="#{fooController.createNewAssignment(foo)}">
            </p:commandButton>
        </h:panelGrid>
        <p:outputPanel id="fooAssignmentsTable">
            <p:dataTable value="#{utils:toList(foo.fooAssignments)}" var="assignment">
                <!-- p:columns here etc..-->
            </p:dataTable>
        </p:outputPanel>

        <p:outputPanel id="assignmentDetail">
            <p:panel rendered="#{not empty fooController.selectedAssignment}" style="margin-top: 30px;">
                <h:panelGrid id="assignmentDetailForm" styleClass="formsTable" columns="2">
                   <!-- Some kick ass code here -->
                </h:panelGrid>
            </p:panel>
        </p:outputPanel>
    </p:panel>
</p:outputPanel>

The problem is, when I hit this page when

 object.category.string == 'foo'

is not satisfied, I am still getting:

/test.xhtml @264,147 value="#{utils:toList(foo.fooAssignments)}": The class 'com.foo.bar.too does not have the property 'fooAssignments'.

Yes, I know this class does not have this property, but this should not be evaluated at all, isn't it?

What am I missing here?

Koray Tugay
  • 22,894
  • 45
  • 188
  • 319

1 Answers1

1

It's unfortunate that you didn't post the full stack trace, as that usually represents the whole answer at its own which I could just translate into layman's terms.

Generally this will indeed happen during a component tree visit whereby the rendered attribute is not obeyed. The mention of the stack trace and the actual versions being used should reveal whether it's a "feature" or actually a bug in either the JSF impl being used, or in PrimeFaces. Generally I'd say that this would be a bug. This problem has before been observed with Mojarra's <ui:repeat> and has been fixed in that side. See also this related Q&A: PropertyNotFoundException on conditionally rendered subclasses in ui:repeat.

If upgrading to latest JSF impl and PrimeFaces version doesn't help, then your best bet is to conditionally build the view instead of conditionally render the view. JSTL is very helpful in this. See also JSTL in JSF2 Facelets... makes sense?

<c:if test="#{object.category.string == 'foo'}">
    <p:panel>
        ...
    </p:panel>
</c:if>
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Primefaces itself has a bug to in its uidata usage in 'repeated' components (e.g. multiple datatables created via a ui:repeat or datatables in datatables.) e.g. https://code.google.com/p/primefaces/issues/detail?id=6276 I've seen similar errors occurring then as stated above. The 'context' for resolving EL seems to be wrong in these cases – Kukeltje Jan 26 '15 at 09:49