【发布时间】:2014-09-03 02:15:20
【问题描述】:
我有一个单一选择的数据表。选择一行并按下按钮后,将打开输入文本和选择一个菜单的对话框。输入文本和一个菜单应包含所选行的数据。一般来说,它是一个用于编辑数据表中记录的对话框。
但是在对话框中选择一个菜单不会根据所选行更改默认值。它适用于<h:selectOneMenu>,但不适用于 Primefaces 的扩展<p:selectOneMenu>。我做错了什么?
我正在使用 Primefaces 5.0 和 JSF 2.1。
XHTML:
<h:form id="form">
<p:dataTable
id="datatable"
var="spec"
value="#{selectionRowAction.specimensBO.list}"
selection="#{selectionRowAction.selectedSpecimen}"
selectionMode="single"
rowKey="#{spec.id}"
resizableColumns="true">
<f:facet name="header">
<p:commandButton id="editButton"
process="datatable"
update=":form:editPanel"
icon="ui-icon-pencil"
oncomplete="PF('dlg').show()"/>
</f:facet>
<p:column headerText="ID" >
<h:outputText value="#{spec.subjectIdNumber}" />
</p:column>
<p:column headerText="Type" >
<h:outputText value="#{spec.specimenType.displayText}" />
</p:column>
</p:dataTable>
<p:dialog widgetVar="dlg" >
<p:outputPanel id="editPanel" >
<p:panelGrid columns="2">
<h:outputText value="ID: "/>
<p:inputText
value="#{selectionRowAction.selectedSpecimen.subjectIdNumber}"/>
<h:outputText value="Type: " />
<p:selectOneMenu
value="#{selectionRowAction.selectedSpecimen.specimenType}"
converter="#{specimenTypeConverter}">
<f:selectItem itemLabel="Select One"/>
<f:selectItems value="#{basicSelectionsBO.specimenTypes}"
var="type"
itemLabel="#{type.displayText}"
itemValue="#{type}"/>
</p:selectOneMenu>
</p:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
【问题讨论】:
-
SpecimenType 类上有 equals() 和 hashCode() 吗?
-
@JaqenH'ghar 感谢您的回复。 SpecimenType 是一个数据模型类,包含带有 getter 和 setter 的属性。我应该覆盖
equals()和hashCode()方法吗? -
I am not sure but I think its a requirement.. when selectmenus gives problems its typically caused by either this or the converter.有关实施,请参见 BalusC 的答案:stackoverflow.com/questions/10726716/…
-
@JaqenH'ghar 太棒了,它正在工作。你能回答我的问题吗?我愿意接受您的解决方案。
-
谢谢,很高兴它成功了
标签: jsf-2 primefaces selectonemenu