2013-12-09 52 views
0

工作我也跟着在这里Demo,但我不知道为什么不工作。我花了3天才解决,但我无法弄清楚我的代码有什么问题。希望有人建议我。PrimeFaces对话框不与数据表

我正在使用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; 
    } 
} 
+0

首先,考虑有两种形式,一种为表本身和其他一个对话框。完成之后,请提供有关您的问题的更多详细信息。是否正确调用了customerBean#setSelectedCustomer?什么''不适合你',对话框不显示? –

+0

@XtremeBiker是兄弟,绑定值工作正常,但对话框不显示。但Makky说我的代码工作得很好。它花了我3天,但我无法弄清楚我的代码有什么问题。 –

回答

0

尝试改变变量名称VAR =” 客户 “VALUE =” #{customerBean。客户} “

+0

我试过,但没有发生任何变化:( –

0

我试过你的代码,它的工作原理。 DebugFireBug并查看是否有任何错误。

+0

真的吗?但我不能看到对话框显示。我真的不知道为什么? –

+0

chat.stackoverflow.com/rooms/42652/myvbhelp – Makky

1

已经测试你的代码,可以确认肯定似乎没有出现任何问题(甚至你可以改进具有独立的形式的话)。在这里你可以找到适合我的SSCCE,自己尝试一下(你应该尽量减少问题的发生,你最好从一些能正常工作的东西开始,并将其适用于具体的情况)。

所有的
@ManagedBean 
@ViewScoped 
public class CustomerBean implements Serializable { 

    /** 
    * 
    */ 
    private static final long serialVersionUID = -6479501676353748761L; 

    private Customer selectedCustomer; 

    private List<Customer> customers = Arrays.asList(new Customer("Andy", 
      "Brown", "A", "[email protected]"), new Customer("George", "Walter", 
      "B", "[email protected]")); 

    public Customer getSelectedCustomer() { 
     return selectedCustomer; 
    } 

    public void setSelectedCustomer(Customer selectedCustomer) { 
     this.selectedCustomer = selectedCustomer; 
    } 

    public List<Customer> getCustomers() { 
     return customers; 
    } 

    public class Customer { 

     public Customer(String firstName, String lastName, String dob, 
       String email) { 
      this.firstName = firstName; 
      this.lastName = lastName; 
      this.dob = dob; 
      this.email = email; 
     } 

     private String firstName; 

     private String lastName; 

     private String dob; 

     private String email; 

     public String getFirstName() { 
      return firstName; 
     } 

     public void setFirstName(String firstName) { 
      this.firstName = firstName; 
     } 

     public String getLastName() { 
      return lastName; 
     } 

     public void setLastName(String lastName) { 
      this.lastName = lastName; 
     } 

     public String getDob() { 
      return dob; 
     } 

     public void setDob(String dob) { 
      this.dob = dob; 
     } 

     public String getEmail() { 
      return email; 
     } 

     public void setEmail(String email) { 
      this.email = email; 
     } 
    } 

} 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:p="http://primefaces.org/ui"> 

<h:head /> 

<h:body> 

    <p:growl id="msgs" showDetail="true" /> 
    <h:form> 
     <p:dataTable id="customers" var="customer" 
      value="#{customerBean.customers}"> 

      <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" oncomplete="carDialog.show()" 
        icon="ui-icon-search" title="View" update=":carDlg"> 
        <f:setPropertyActionListener value="#{customer}" 
         target="#{customerBean.selectedCustomer}" /> 
       </p:commandButton> 
      </p:column> 

     </p:dataTable> 
    </h:form> 

    <p:dialog header="Car Detail" widgetVar="carDialog" resizable="false" 
     id="carDlg" showEffect="fade" hideEffect="explode"> 
     <h:form id="dialog_form"> 

      <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> 

     </h:form> 
    </p:dialog> 

</h:body> 

</html> 
+0

但我对话框不显示。能它受到了jquery bro的影响吗? –

+0

只需将它复制粘贴到你的项目中,看看它是否有效,并将它应用到你正在做的事情中。 –

+0

你的代码工作的很好,我只是实现了Serializable并且改变了范围来查看,牛逼的工作。你需要我的项目进行检查。 –