【发布时间】:2013-12-09 12:43:01
【问题描述】:
我在这里关注Demo,但我不知道为什么不起作用。我花了 3 天时间才解决,但我无法弄清楚我的代码有什么问题。希望有人建议我。
我正在使用 Hibernate + JSF 2.0 + PrimeFaces 3.5。
xhtml
<h:form id="form">
<p:growl id="msgs" showDetail="true" />
<p:dataTable id="customers" var="customer" value="#{customerBean.customer}">
<p:column headerText="Model" style="width:24%">
<h:outputText value="#{customer.firstName}" />
</p:column>
<p:column headerText="Year" style="width:24%">
<h:outputText value="#{customer.lastName}" />
</p:column>
<p:column headerText="Manufacturer" style="width:24%">
<h:outputText value="#{customer.dob}" />
</p:column>
<p:column headerText="Color" style="width:24%">
<h:outputText value="#{customer.email}" />
</p:column>
<p:column style="width:4%">
<p:commandButton id="selectButton" update=":form:display" oncomplete="carDialog.show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{customer}" target="#{customerBean.selectedCustomer}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Car Detail" widgetVar="carDialog" resizable="false" id="carDlg"
showEffect="fade" hideEffect="explode">
<h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">
<h:outputText value="Model:" />
<h:outputText value="#{customerBean.selectedCustomer.firstName}" style="font-weight:bold"/>
<h:outputText value="Year:" />
<h:outputText value="#{customerBean.selectedCustomer.lastName}" style="font-weight:bold"/>
<h:outputText value="Manufacturer:" />
<h:outputText value="#{customerBean.selectedCustomer.dob}" style="font-weight:bold"/>
<h:outputText value="Color:" />
<h:outputText value="#{customerBean.selectedCustomer.email}" style="font-weight:bold"/>
</h:panelGrid>
</p:dialog>
</h:form>
customerBean (RequestScoped)
public class customerBean {
private List<Customer> customer;
private Customer selectedCustomer;
/** Creates a new instance of customerBean */
public customerBean() {
customer = new ArrayList<Customer>();
}
public List<Customer> getCustomer() {
CustomersDao cust_dao = new CustomersDao();
customer = cust_dao.findAll();
return customer;
}
public Customer getSelectedCustomer() {
return selectedCustomer;
}
public void setSelectedCustomer(Customer selectedCustomer) {
this.selectedCustomer = selectedCustomer;
}
}
【问题讨论】:
-
首先,考虑有两种形式,一种用于表格本身,另一种用于对话框。完成后,请提供有关您的问题的更多详细信息。
customerBean#setSelectedCustomer是否被正确调用?doesn't working对你来说是什么,对话框根本没有显示? -
@XtremeBiker 是的,兄弟,绑定值工作正常,但没有显示对话框。但 Makky 说我的代码运行良好。我花了 3 天的时间,但我无法弄清楚我的代码有什么问题。
标签: java jsf primefaces datatable