通过使用链接到bean中的HashMap的h:selectbooleanCheckbox使h:dataTable单元格可编辑

时间:2011-09-21 14:24:22

标签: jsf jsf-1.2

我从SO那里经历了这个问题 How to use <h:selectBooleanCheckbox> in <h:dataTable> to select multiple rows?

使用上面问题所示的单一复选框,我想知道是否可以使h:datatable cell可编辑,以便用户可以一次编辑所有行和列并提交

这是bean类的一部分

public class bean {
private List<Group> GroupList;

private Map<Long, Boolean> checked = new HashMap<Long, Boolean>();

public void setChecked(Map<Long, Boolean> checked) {
    this.checked = checked;
}

public Map<Long, Boolean> getChecked() {
    return checked;
}


}

这是我的JSF页面

<h:dataTable id="editTable" styleClass = "listtable" value="#{bean.GroupList}"  var="group" border="1" first="0" rows="8" width="75%" frame="hsides" rules="all" cellpadding="5" headerClass="tableheading" rowClasses="firstrow, secondrow">

    <f:facet name="header">
    <h:outputText value="Groups"></h:outputText>
    </f:facet>

    <h:column>
        <f:facet name="header">
        <h:outputText value="GroupId"></h:outputText>
        </f:facet>
        <h:outputText value="#{group.Id}" rendered=""></h:outputText>
        <h:inputText value="#{group.Id}" rendered=""/>
    </h:column>

    <h:column>
        <f:facet name="header">
        <h:outputText value="GroupName"></h:outputText>
        </f:facet>
        <h:outputText value="#{group.Name}" rendered=""></h:outputText>
        <h:inputText value="#{group.Name}" rendered=""/>
    </h:column>


    <h:column>
        <f:facet name="header">
        <h:outputText value="Check to Enable/Disable"></h:outputText>
        </f:facet>
        <h:selectBooleanCheckbox value="#{bean.checked[group.Id]}" />
    </h:column>

    </h:dataTable>

渲染属性中应该保留什么,以便在检查时h:呈现inputtext并且在未检查时h:呈现outputtext?

1 个答案:

答案 0 :(得分:1)

只需绑定到同一个属性即可。无论如何它返回Boolean。您可以使用!not来否定它。

<h:outputText value="#{group.Id}" rendered="#{!bean.checked[group.Id]}" />
<h:inputText value="#{group.Id}" rendered="#{bean.checked[group.Id]}" />
...
<h:outputText value="#{group.Name}" rendered="#{!bean.checked[group.Id]}" />
<h:inputText value="#{group.Name}" rendered="#{bean.checked[group.Id]}" />
相关问题