PrimeFaces dataTable rowEditor不适用于列表对象

时间:2015-04-18 04:11:36

标签: jsf-2 primefaces

当我在dataTable中编辑String,Integer和Enums时,primefaces rowEditor事件对我有用,但是当我尝试更新对象列表时,onRowEdit事件不会执行。我已经提供了以下代码,如果需要更多信息,请告诉我。

环境PF5.2,JSF 2.2,GF 4.0及其maven项目

student.xhtml页面

<p:dataTable id="dataTable" value="#{student.students}" var="item" editable="true">
     <p:column headerText="course">
         <p:cellEditor>
           <f:facet name="output">
              <h:outputText value="#{item.course.name}" />
           </f:facet>
           <f:facet name="input">
              <h:selectOneMenu value="#{item.course}"> 
                  <f:selectItems value="#{student.courses}" var="_course" itemValue="#{_course}" itemLabel="#{_course.name}"/>
              </h:selectOneMenu>
           </f:facet>
        </p:cellEditor>
      </p:column>
      <p:ajax event="rowEdit" listener="#{student.onRowEdit}" update="dataTable"/>
      <p:ajax event="rowEditCancel" listener="#{student.onRowCancel}" update="dataTable" />
      <p:column style="width:32px">
         <p:rowEditor/>
      </p:column>

@Named("student")
@ViewScoped
public class StudentManager implements Serializable {

    private static final long serialVersionUID = 9196263323752494128L;

    private List<Students> students = new ArrayList<>();
    private List<Course> courses = new ArrayList<>();


    @PostConstruct
    public void init() {
       students = service.getStudents();
       courses  = service.getCources();
    }

    public void onRowEdit(RowEditEvent event) {
      //do something
    }

    public void onRowCancel(RowEditEvent event) {
     //do nothing
    }

    //getters and setters
    ------
    ------
}

对象

@Entity
@Table(name="student")
public class Student implements Serializable {
  ---
  private Integer id;
  private String firstName;
  private String lastName;
  private Course course;

  ---

}



@Entity
@Table(name="course")
public class Course implements Serializable {
  ---
  private Integer id;
  private String courseName;

  ---

}

0 个答案:

没有答案