4

I have a data table that will display a detail dialog on row select event. However, the dialog does not show any values of the selected object. I can see that the selected object is properly set during debug session.

The table consists of rows of students and it is suppose to display a popup dialog showing detailed information on row selection event.

The 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);  
        }


    }

The Facelet page:

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

I'm following the Car data table example from the Primefaces Showcase page. It seems so simple there but I can't seem to display the selectedStudent information no matter what I do. The dialog shows up fine but the firstName and lastName values are empty.

I tried the following:

  • Putting the dialog into another form
  • Use process="@form"
  • Use process=":studentForm:studentDetail"

What am I doing wrong?

Primefaces 3.3.1, Glassfish 3.1.2

Random Joe
  • 640
  • 4
  • 10
  • 25
  • by default the form is processed. also, moving the dialog to a different form won't help. try removing the immediate attribute (or set it to false, which is the default). I don't see that in the showcase – damian Aug 07 '12 at 11:51
  • Hi @Damian I tried to follow the example as closely as I can without the immediate attribute at first. It just refused to work :( . – Random Joe Aug 10 '12 at 16:35
  • Wrap table with an panelGroup and try to pass that panelGroup in process. – Jitesh Mar 26 '13 at 18:26

1 Answers1

0

I removed global="true" immediate="true", unused listeners

from p:ajax, synchronized rowKey="#{student.id}" 

with expression from "Student ID" column and populated studentList inside @PostConstruct init() function not knowing how yours userFacade code is, and it works.

Raul Cacacho
  • 267
  • 1
  • 4
  • 15