2012-08-06 43 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代码是怎样的,它的工作原理。

相关问题