JSF重复nog显示复选框中的值

时间:2022-03-04 20:05:07

I'm passing a hashmap which consists out of an object + a boolean into my view and I want to display the value of the boolean of each object and currently have the following code:

我正在将一个由对象+布尔值组成的散列图传递到我的视图中,并且我希望显示每个对象的布尔值,并且当前具有以下代码:

<ui:repeat var="item" value="#{userTypeController.permissionItems}">
                    <h:outputText value="#{item}" />
                    <h:selectBooleanCheckbox value="#{userTypeController.checkMap[item]}"/>
    </ui:repeat>

And the Hashmap method:

和Hashmap方法:

    public Map<Permission, Boolean> getCheckMap() {
    checkMap = null;
    for (Permission p : getPermissionItems()) {
        if (getPermissionItemsUserType().contains(p))
            checkMap.put(p, Boolean.TRUE);
        else
            checkMap.put(p, Boolean.FALSE);
        System.out.println(checkMap.get(p).toString());
    }
    return checkMap;
}

This should work and during the system.out.println I see a true output...

这应该工作,并在system.out.println期间,我看到一个真正的输出...

However, the checkboxes itself are never checked... Any idea on what I'm doing wrong here?

但是,复选框本身永远不会被检查......对于我在这里做错了什么?

1 个解决方案

#1


0  

The symptoms which you describe matches Mojarra bug 1807 which was by coincidence fixed in 2.1.1 and was officially fixed in 2.1.4. So, upgrading Mojarra to at least 2.1.1 should do.

你描述的症状符合Mojarra bug 1807,这是在2.1.1中巧合,并在2.1.4中正式确定。因此,将Mojarra升级至至少2.1.1应该可以。

Note that you've a major bug in your code. You are nowhere instantiating the checkmap, it would throw a NullPointerException, although this seems to be oversimplifying of the code for the question. Also, doing this inside a getter is a bad idea. It should be done during the (post)construct or an event listener method. A getter can be called more than once during render response. See also Why JSF calls getters multiple times.

请注意,您的代码中存在一个主要错误。你无处实例化checkmap,它会抛出一个NullPointerException,虽然这似乎过于简化了问题的代码。此外,在吸气剂内执行此操作是个坏主意。它应该在(post)构造或事件监听器方法期间完成。在渲染响应期间,可以多次调用getter。另请参见为什么JSF多次调用getter。

#1


0  

The symptoms which you describe matches Mojarra bug 1807 which was by coincidence fixed in 2.1.1 and was officially fixed in 2.1.4. So, upgrading Mojarra to at least 2.1.1 should do.

你描述的症状符合Mojarra bug 1807,这是在2.1.1中巧合,并在2.1.4中正式确定。因此,将Mojarra升级至至少2.1.1应该可以。

Note that you've a major bug in your code. You are nowhere instantiating the checkmap, it would throw a NullPointerException, although this seems to be oversimplifying of the code for the question. Also, doing this inside a getter is a bad idea. It should be done during the (post)construct or an event listener method. A getter can be called more than once during render response. See also Why JSF calls getters multiple times.

请注意,您的代码中存在一个主要错误。你无处实例化checkmap,它会抛出一个NullPointerException,虽然这似乎过于简化了问题的代码。此外,在吸气剂内执行此操作是个坏主意。它应该在(post)构造或事件监听器方法期间完成。在渲染响应期间,可以多次调用getter。另请参见为什么JSF多次调用getter。