简体   繁体   English

列表包含在JSF页面中不起作用的方法

[英]List contains method not working in JSF page

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. 我已经更改了equals和hashcode方法,但并没有帮助。

JSTL tags like <c:if> runs during view build time and the result is JSF components only. 诸如<c:if>类的JSTL标记在视图构建期间运行,结果仅是JSF组件。 JSF components runs during view render time and the result is HTML only. JSF组件在视图渲染期间运行,结果仅为HTML。 They do not run in sync. 它们不同步运行。 JSTL tags runs from top to bottom first and then JSF components runs from top to bottom. JSTL标记首先从上到下运行,然后JSF组件从上到下运行。

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 . 在您的情况下,当JSTL标记运行时,在任何地方都没有#{item} ,因为它是由JSF组件定义的,因此对于JSTL而言,它将始终被评估为null You need to use JSF components instead. 您需要使用JSF组件。 In your particular case a <h:panelGroup rendered> should do it: 在您的特定情况下, <h:panelGroup rendered>应该这样做:

<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: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM