简体   繁体   English

JSF重复点此在复选框中显示值

[英]JSF Repeat nog showing value in checkbox

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? 但是,复选框本身从未被选中...对我在这里做错的任何想法吗?

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. 您描述的症状与Mojarra错误1807相匹配, 该错误恰巧是在2.1.1中修复的,并在2.1.4中已正式修复。 So, upgrading Mojarra to at least 2.1.1 should do. 因此,应该 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. 您无处实例化checkmap ,它将抛出NullPointerException ,尽管这似乎过分简化了该问题的代码。 Also, doing this inside a getter is a bad idea. 此外,在吸气剂中进行此操作也是一个坏主意。 It should be done during the (post)construct or an event listener method. 它应该在(post)构造或事件侦听器方法期间完成。 A getter can be called more than once during render response. 在渲染响应期间,可以多次调用一个吸气剂。 See also Why JSF calls getters multiple times . 另请参见为什么JSF多次调用getter

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

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