Primefaces3 - dataTable with confir. dialog issue

UI Components for JSF
Post Reply
igor22
Posts: 7
Joined: 13 May 2011, 05:37

21 May 2011, 05:29

Hi,
I created an example of dataTable with delete button which opens a confirmation dialog with Yes/No. If yes is chosen the selected table row should be deleted.
When the "Delete" icon is clicked I am setting myBean.selectedStudentCourse to the dataTable's var value. That works fine, the method
setSelectedStudentCourse() gets called. Now, when "Yes" button is clicked on the confirmation dialog, I am calling the method myBean.delete() and I expect
the value "selectedStudentCourse" in this method to be preserved but it's not. It is null. My bean class is view scoped. Does anybody know why the variable selectedStudentCourse
is being reset to null between methods setSelectedStudentCourse() and delete() ?

xhtml:
...
<h:body>
<h:form id="form" prependId="false">
<p:dataTable id="myTable" var="studentCourse" value="#{myBean.studentCourseList}">

<p:column>
Profesor: <h:outputText value="#{studentCourse.professor}"/>
</p:column>

<!-- Delete icon that opens confirm. dialog: -->
<p:column style="width:58px;">
<p:commandLink oncomplete="confirmationDialog.show()">
<f:setPropertyActionListener value="#{studentCourse}" target="#{myBean.selectedStudentCourse}" />
<h:graphicImage value="../resources/images/delete_icon.png" style="width: 13px; height: 13px; border-style: none;" title="Delete" />
</p:commandLink>

</p:column>
</p:dataTable>

<p:confirmDialog widgetVar="confirmationDialog"
message="Are you sure you want to remove this course from your list of courses?"
modal="true"
header="Delete Confirmation" severity="alert" >

<p:commandButton value="Yes" action="#{myBean.delete}"
update="myTable" oncomplete="confirmationDialog.hide()"/>
<p:commandButton value="No" onclick="confirmationDialog.hide()" type="button"/>
</p:confirmDialog>
</h:form>
</h:body>
...

MyBean:
...
@ManagedBean
@ViewScoped
public class MyBean {

private List<StudentCourse> studentCourseList = null;
private StudentCourse selectedStudentCourse;

public StudentCourse getSelectedStudentCourse() {
return selectedStudentCourse;
}
public void setSelectedStudentCourse(StudentCourse selectedStudentCourse) {
System.out.println("In setSelectedtudentCourse()...");
this.selectedStudentCourse = selectedStudentCourse;
}

public List<StudentCourse> getStudentCourseList() {
List<StudentCourse> l = new ArrayList<StudentCourse>();
StudentCourse sc = new StudentCourse();
sc.setProfessor("Jack Palance");
l.add(sc);
return l;
}

public void delete() {
System.out.println("In delete(): selectedStudentCourse = " + selectedStudentCourse); //it's null !!??
}
}

Thanks.

igor22
Posts: 7
Joined: 13 May 2011, 05:37

21 May 2011, 13:46

Alex's suggestion (from another post) to add process="@this" to my commandLink solved the problem. Thanks.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 8 guests