简体   繁体   English

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

[英]Make h:dataTable cell editable by using h:selectbooleanCheckbox linked to HashMap in the bean

I went through this question from SO How to use <h:selectBooleanCheckbox> in <h:dataTable> to select multiple rows? 我从SO中解决了这个问题, 如何在<h:dataTable>中使用<h:selectBooleanCheckbox>选择多行?

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 使用上面问题中所示的单个复选框,我想确定我是否可以使h:datatable单元格可编辑,以便用户可以一次编辑所有行和列并提交

Here is part of bean class 这是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;
}


}

And here is my JSF page 这是我的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>

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? 应该在render属性中保留什么,以便在选中h:inputtext时显示它,而在不选中h:outputtext时显示呢?

Just bind to the same property. 只需绑定到相同的属性。 It returns a Boolean anyway. 无论如何,它返回一个Boolean You can use ! 您可以使用! or not to negate it. 还是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]}" />

暂无
暂无

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

相关问题 如何在ah:dataTable中的ah:dataTable中映射ah:selectBooleanCheckbox的值? - How to map the value of a h:selectBooleanCheckbox in a h:dataTable within a h:dataTable? 使用bean的方法结果时的PropertyNotFoundException <h:selectBooleanCheckbox/> - PropertyNotFoundException when using bean's method's result for <h:selectBooleanCheckbox/> 运用 <h:selectBooleanCheckbox> 在分页中使用地图 <p:dataTable> 抛出NullPointerException - Using <h:selectBooleanCheckbox> with Map in a paginated <p:dataTable> throws NullPointerException 使用h:selectBooleanCheckbox和c:if来获取a的行值 <rich:datatable> -JSF - Using h:selectBooleanCheckbox with c:if to obtain row value of a <rich:datatable> - JSF 使用h:selectBooleanCheckbox删除JSF数据表中的多行 - Using h:selectBooleanCheckbox to delete multiple rows in JSF datatable 使用分页时,在rich:dataTable中选择的h:selectBooleanCheckbox丢失 - h:selectBooleanCheckbox being selected in rich:dataTable is lost when using Pagination 如何选择多个行 <h:dataTable> 同 <h:selectBooleanCheckbox> - How to select multiple rows of <h:dataTable> with <h:selectBooleanCheckbox> Commandbutton仅在第二次单击时起作用,直到出现 <h:selectBooleanCheckbox> 在HashMap上被删除 - Commandbutton works only on second click until a <h:selectBooleanCheckbox> on a HashMap is removed 在h:selectBooleanCheckbox的disabled属性中使用negation - Using negation in disabled attribute of h:selectBooleanCheckbox 如何在后备bean中获取h:selectBooleanCheckbox的ID属性 - How to get the ID attribute of h:selectBooleanCheckbox in backing bean
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM