0

I have two list that consist out of the same object.

I want to check if the first list containts an object of the second list

<ui:repeat var="item" value="#{userTypeController.permissionItems}">
    <c:if test="#{userTypeController.permissionItemsUserType.contains(item)}">
        <h:selectBooleanCheckbox value="#{true}"/> 
        <h:outputText value="#{item.getAction()}" />
    </c:if>
    <c:if test="#{!userTypeController.permissionItemsUserType.contains(item)}">
        <h:selectBooleanCheckbox value="#{false}"/> 
        <h:outputText value="#{item.getAction()}" />
    </c:if>
</ui:repeat>

but this doesn't seem to work and all I'm getting is false.

I've changed the equals and hashcode methodes but didn't help.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ThomasVdBerge
  • 7,483
  • 4
  • 44
  • 62

1 Answers1

1

JSTL tags like <c:if> runs during view build time and the result is JSF components only. JSF components runs during view render time and the result is HTML only. They do not run in sync. JSTL tags runs from top to bottom first and then JSF components runs from top to bottom.

In your case, when JSTL tags runs, there's no means of #{item} anywhere, because it's been definied by a JSF component, so it'll for JSTL always be evaluated as if it is null. You need to use JSF components instead. In your particular case a <h:panelGroup rendered> should do it:

<ui:repeat var="item" value="#{userTypeController.permissionItems}">
    <h:panelGroup rendered="#{userTypeController.permissionItemsUserType.contains(item)}">
        <h:selectBooleanCheckbox value="#{true}"/> 
        <h:outputText value="#{item.getAction()}" />
    </h:panelGroup>
    <h:panelGroup rendered="#{!userTypeController.permissionItemsUserType.contains(item)}">
        <h:selectBooleanCheckbox value="#{false}"/> 
        <h:outputText value="#{item.getAction()}" />
    </h:panelGroup>
</ui:repeat>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555