[英]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.