行选择事件ajax不起作用(未触发)

时间:2019-07-12 08:52:39

标签: ajax jsf primefaces

假设顶层有一个班级的学生。我的问题是,当我在debug中运行代码并在方法onRowSelect中放入一些breackpoints时,但是当我选择该行时,代码不会转到断点,而是显示对话框但显示出值。 / p>

search.xhtml:

<h:form id="form">  
         <p:dataTable id="resultStudent" var="student" lazy="true" value="#{studentBean.listStudents}"  selectionMode="single"  selection="#{studentBean.selectedStudent}" rows="10"
                 paginator="true"
                 paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                 rowsPerPageTemplate="2,5,10,15" rowKey="#{student.idStudent}">
                 <!-- This is the problem -->
             <p:ajax event="rowSelect" listener="#{studentBean.onRowSelect}" update=":form:StrudentDetail" oncomplete="PF('studentDialog').show()" process="resultStudent"/>     
....

</p:dataTable>

<!-- The dialog is -->

        <p:dialog header="Detaails Student" widgetVar="studentDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
        <p:outputPanel id="StudentDetail" style="text-align:center;">
            <p:panelGrid  columns="2" rendered="#{not empty studentBean.selectedStudent}" columnClasses="label,value">
                <f:facet name="header">
                  <!--   <p:graphicImage name="demo/images/car/#{dtLazyView.selectedCar.brand}-big.gif"/>-->
                </f:facet>

StudentBean类为:

@ManagedBean(name = "studentBean")
@ViewScoped
public class StudentBean {
... AAL method get and set
private Student selectedStudent;

@PostConstruct
    public void init() {...

}

 public void onRowSelect(SelectEvent event) {
//THis I put the debug and the code doesn't seem execute here

            int id=(Student)event.getObject()).getIdStudent());
            FacesMessage msg = new FacesMessage("Student Selected");
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

您的代码中有一个错字,很可能导致对话框不使用后备bean中的新值更新。

p:ajax rowSelect事件具有定义的属性update=":form:StrudentDetail"。但是,您真正想要更新的是:form:StudentDetail

您没有指定您正在运行的JSF或EE版本。值得一提的是,自JSF 2.3起不推荐使用@ManagedBean。因此,如果这是一个新应用程序,则应迁移到@Named和CDI。