Primefaces selectOneMenu中的CustomContent而不保留对象 [英] CustomContent in Primefaces selectOneMenu without persisting object
问题描述
我正在使用Primefaces SelectOneMenu( http://www.primefaces.org /showcase-labs/ui/selectOneMenu.jsf ),如演示中所述,带有自定义内容"版本.
问题在于,只有绑定到下拉字段的字段的实际值是用作value
的对象的类型时,这些列才起作用.
以下工作原理(如果Bean.field
是SelectObject
类型):
<p:selectOneMenu value="#{bean.field}"
var="x">
<f:selectItems
value="#{valuesBean.getSelectItems()}" var="bt"
itemLabel="#{bt.label}" itemValue="#{bt}" />
<p:column>
<h:outputText
value="#{x.value}" />
</p:column>
<p:column>
<h:outputText value="xyz" />
</p:column>
</p:selectOneMenu>
以下内容不起作用(类型为String
的Bean.field
):
<p:selectOneMenu value="#{bean.field}"
var="x">
<f:selectItems
value="#{valuesBean.getSelectItems()}" var="bt"
itemLabel="#{bt.label}" itemValue="#{bt.value}" />
<p:column>
<h:outputText
value="#{x.value}" />
</p:column>
<p:column>
<h:outputText value="xyz" />
</p:column>
</p:selectOneMenu>
在第一个版本中,xyz
显示为第二列,而在第二个版本中则不显示.我的问题是,尽管我也可以只将value
字段的字符串保存在那里,现在我需要在数据库中保存一个SelectObject
类型的对象.
有解决这个问题的好方法吗?
使用转换器将所选菜单项的值(bt.value)转换为与p:selectOneMenu(bean: .场地).
<p:selectOneMenu value="#{bean.field}" var="x" converter="yourconverterid">
I am using the Primefaces SelectOneMenu (http://www.primefaces.org/showcase-labs/ui/selectOneMenu.jsf) with the "Custom content" version as described in the demo.
The problem is that the columns only work if the actual value of the field, which is bound to the dropdown field, is of the type of the Object used as the value
.
The following works (if Bean.field
is of type SelectObject
):
<p:selectOneMenu value="#{bean.field}"
var="x">
<f:selectItems
value="#{valuesBean.getSelectItems()}" var="bt"
itemLabel="#{bt.label}" itemValue="#{bt}" />
<p:column>
<h:outputText
value="#{x.value}" />
</p:column>
<p:column>
<h:outputText value="xyz" />
</p:column>
</p:selectOneMenu>
The following does NOT work (Bean.field
of type String
):
<p:selectOneMenu value="#{bean.field}"
var="x">
<f:selectItems
value="#{valuesBean.getSelectItems()}" var="bt"
itemLabel="#{bt.label}" itemValue="#{bt.value}" />
<p:column>
<h:outputText
value="#{x.value}" />
</p:column>
<p:column>
<h:outputText value="xyz" />
</p:column>
</p:selectOneMenu>
In the first version, the xyz
is displayed as second column, in the second version it's not. The problem I have is that now I need to save an object of type SelectObject
in the database although I could as well just save the String of the value
field there.
Is there a nice way to handle this?
Use a Converter to convert the value of the selected menu item (bt.value) to that expected by the backing bean method tied to the p:selectOneMenu (bean.field).
<p:selectOneMenu value="#{bean.field}" var="x" converter="yourconverterid">
这篇关于Primefaces selectOneMenu中的CustomContent而不保留对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!