java 数据表中的 JSF / Primefaces selectBooleanCheckbox 组件始终未选中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15953623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSF / Primefaces selectBooleanCheckbox component in dataTable always unchecked
提问by OguzOzkeroglu
In my project i'm using JSF 2.0 and Primefaces 3.5.
在我的项目中,我使用的是 JSF 2.0 和 Primefaces 3.5。
In one page i have a p:dataTable
and the tables one column has selectBooleanCheckbox
. I tried both of p:selectBooleanCheckbox
and h:selectBooleanCheckbox
. My code like as follow:
在一页中,我有一个p:dataTable
,而一列有表格selectBooleanCheckbox
。我尝试了p:selectBooleanCheckbox
和h:selectBooleanCheckbox
。我的代码如下:
<h:panelGrid columns="3">
<p:selectBooleanCheckbox id="id" value="false" />
<p:selectBooleanCheckbox id="id" value="true" />
<p:dataTable id="tbl" value="#{bean.items}" var="item" paginator="false">
<p:column>
<h:outputText value="#{item.value}" />
</p:column>
<p:column>
<h:outputText value="#{item.value}" />
</p:column>
<p:column style="white-space:normal; text-align: center;">
<p:selectBooleanCheckbox id="id" value="#{item.checked}" />
<p:selectBooleanCheckbox id="id" value="true" />
<p:selectBooleanCheckbox id="id" value="false" />
<h:selectBooleanCheckbox id="id" value="true" />
<h:selectBooleanCheckbox id="id" value="false" />
</p:column>
</p:dataTable>
</h:panelGrid>
And the result:
结果:
I want to show correct case of selectBooleanCheckbox. Any suggestions?
我想显示 selectBooleanCheckbox 的正确大小写。有什么建议?
采纳答案by James Gilchrist
You do not seem to be linking the checkbox to any value in your backing bean. Try storing the value in your backing bean and having it be reflected in your checkbox. For instance,
您似乎没有将复选框链接到支持 bean 中的任何值。尝试将值存储在您的支持 bean 中并使其反映在您的复选框中。例如,
Backing Bean:
支持豆:
private Boolean value1 = true;
private Boolean value2 = false;
//appropriate getters and setters for the above values
JSF Page Fragment:
JSF 页面片段:
<p:selectBooleanCheckbox value="#{backingbean.value1}" itemLabel="Value 1"/>
<p:selectBooleanCheckbox value="#{backingbean.value2}" itemLabel="Value 2"/>
This should result in the first checkbox being checked (because value1 = true) and the second should not be as value2 = false. In this manner, whenever you click a checkbox it's value will also be reflected in value1 and value2 respectively.
这应该导致第一个复选框被选中(因为 value1 = true),第二个不应该是 value2 = false。以这种方式,每当您单击复选框时,它的值也将分别反映在 value1 和 value2 中。
Hope that helps...
希望有帮助...
Also, @navand is correct in saying to use #{true} and #{false} if you want to manually set the checkbox to be checked or not.
此外,@navand 说使用 #{true} 和 #{false} 是正确的,如果您想手动设置复选框是否被选中。
回答by navand
You should use #{true}
or #{false}
instead of true
or false
like this:
您应该使用#{true}
or#{false}
代替true
orfalse
像这样:
<p:selectBooleanCheckbox id="id" value="#{true}" />