2012-08-06 70 views
4

我有一個數據表,它將顯示行選擇事件的詳細信息對話框。但是,該對話框不顯示所選對象的任何值。我可以看到在調試會話期間正確設置了所選對象。Primefaces ajax行選擇無法更新對話框中的值

該表由多行學生組成,它假定顯示一個彈出式對話框,顯示行選擇事件的詳細信息。

的StudentBean:

@Named(value = "studentBean") 
@SessionScoped 
public class StudentBean { 

     @Inject 
     private UserFacade userFacade; 
     private List<User> studentList; 
     private User selectedStudent; 


     public StudentBean() { 
     } 

     @PostConstruct 
     public void init() { 
      studentList = userFacade.findAll(); 

     } 


     public List<User> getStudentList() { 
      return studentList; 

     } 


     public void setStudentList(List<User> studentList) { 
      this.studentList = studentList; 
     } 


     public User getSelectedStudent() { 
      return selectedStudent; 
     } 


     public void setSelectedStudent(User student) { 
      this.selectedStudent = student; 
     } 

     public void onRowSelect(SelectEvent event) { 
     } 

     public void onRowUnselect(UnselectEvent event) { 
      //FacesMessage msg = new FacesMessage("Student Unselected", ((User) event.getObject()).getFirstName()); 
      //FacesContext.getCurrentInstance().addMessage("messages", msg); 
     } 


    } 

的一個facelet頁:

<?xml version='1.0' encoding='UTF-8' ?> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:ui="http://java.sun.com/jsf/facelets" 
      xmlns:h ="http://java.sun.com/jsf/html" 
      xmlns:p ="http://primefaces.org/ui"> 

     <body> 

      <ui:composition template="./layout.xhtml"> 

       <ui:define name="content"> 
        <h:form id="studentForm"> 


         <p:dataTable var="student" value="#{studentBean.studentList}" 
            selectionMode="single" 
            selection="#{studentBean.selectedStudent}" rowKey="#{student.id}"> 

          <p:ajax event="rowSelect" listener="#{studentBean.onRowSelect}" 
            update=":studentForm:studentDetail" oncomplete="studentDialog.show()" 
            global="true" immediate="true" 
            /> 
          <p:ajax event="rowUnselect" listener="#{studentBean.onRowUnselect}" /> 


          <p:column headerText="First Name"> 
           <h:outputText value="#{student.firstName}" /> 
          </p:column> 

          <p:column headerText="Last Name"> 
           <h:outputText value="#{student.lastName}" /> 
          </p:column> 

          <p:column headerText="Student ID"> 
           <h:outputText value="#{student.studentid}" /> 
          </p:column> 

         </p:dataTable> 



         <p:dialog id="dialog" header="Student Detail" widgetVar="studentDialog" resizable="false" 
            showEffect="fade" hideEffect="fade" appendToBody="true"> 

          <h:panelGrid id="studentDetail" columns="2" cellpadding="4"> 

           <h:outputText value="First Name: " /> 
           <h:outputText value="#{studentBean.selectedStudent.firstName}" /> 

           <h:outputText value="Last Name: " /> 
           <h:outputText value="#{studentBean.selectedStudent.lastName}" /> 

          </h:panelGrid> 
         </p:dialog> 
       </ui:define> 

      </ui:composition> 

     </body> 
    </html> 

我下面從Primefaces展示頁面的汽車數據表的例子。這似乎很簡單,但我似乎無法顯示選定的學生信息,無論我做什麼。該對話框顯示正常,但firstName和lastName值爲空。

我試過如下:

  • 把對話變成另一種形式
  • 使用過程= 「@形式」
  • 使用過程= 「:studentForm:studentDetail」

什麼我做錯了嗎?

Primefaces 3.3.1, Glassfish的3.1.2

+0

默認情況下處理表格。另外,將對話框移到不同的表單也無濟於事。嘗試刪除即時屬性(或將其設置爲false,這是默認設置)。我在展示中看不到 – Damian 2012-08-07 11:51:19

+0

Hi @Damian我試圖儘可能嚴密地遵循這個例子,一開始就沒有立即的屬性。它只是拒絕工作:(。 – 2012-08-10 16:35:49

+0

我正面臨同樣的問題。你找到一個解決方案嗎? – 2012-11-15 20:54:07

回答

0

我除去全球= 「真」 立即= 「真」,從對未使用的監聽器:AJAX,同步rowKey = 「#{student.id}」 與表達式從「學生ID」列填充 studentList裏面的@PostConstruct init()函數不知道你的userFacade代碼是怎樣的,它的工作原理。