通过使用链接到 bean 中的 HashMap 的 h:selectbooleanCheckbox 使 h:dataTable 单元格可编辑
我从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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需绑定到相同的属性即可。无论如何,它都会返回一个布尔值。您可以使用
!
或not
来否定它。Just bind to the same property. It returns a
Boolean
anyway. You can use!
ornot
to negate it.