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

发布于 2024-12-05 15:02:53 字数 2096 浏览 4 评论 0原文

我从SO那里问过这个问题 如何使用;在中选择多行?

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

这是部分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>

rendered 属性中应该保留什么,以便在选中它时呈现 h:inputtext ,在不选中时呈现 h:outputtext ?

I went through this question from SO
How to use <h:selectBooleanCheckbox> in <h:dataTable> to select multiple rows?

Using the single checkbox as shown in above question i want to find out whether i can make h:datatable cell editable so that user can edit all the rows and columns at once and submit

Here is part of bean class

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;
}


}

And here is my JSF page

<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>

What should be kept in rendered attribute so that when it is checked h:inputtext is rendered and when not checked h:outputtext is rendered?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海不蓝 2024-12-12 15:02:53

只需绑定到相同的属性即可。无论如何,它都会返回一个布尔值。您可以使用 !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]}" />

Just bind to the same property. It returns a Boolean anyway. You can use ! or not to negate it.

<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]}" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文