Primefaces3 -dataTable row with edit button

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

21 May 2011, 06:19

Hi,

I have a dataTable whose each row has an edit button. When that button is clicked I am trying to set myBean.selectedStudentCourse to the dataTable's var variable
using <f:setPropertyActionListener value="#{studentCourse}" target="#{myBean.selectedStudentCourse}" /> and open the edit dialog. It is very strange, if I have an input field (in my edit dialog) whose required="true" the method setSelectedStudentCourse() never gets called. When I remove required="true" that method gets called.

<h:form id="form" prependId="false"
<p:dataTable id="myTable" var="studentCourse" value="#{myBean.studentCourseList}">
<p:column>
Professor: <h:outputText value="#{studentCourse.professor}"/>
</p:column>

<p:column style="width:58px;">
<p:commandLink oncomplete="myEditDialog.show()">
<f:setPropertyActionListener value="#{studentCourse}" target="#{myBean.selectedStudentCourse}" />
<h:graphicImage value="../resources/images/edit_icon2.png" style="width: 13px; height: 13px; border-style: none;" title="Delete" />
</p:commandLink>
</p:column>
</p:dataTable>

<p:dialog header="Edit Course" widgetVar="myEditDialog" resizable="false" id="courseDlg"
width="400" showEffect="fade" hideEffect="explode" modal="true">
<p:outputPanel id="display">
<h:panelGrid columns="2" border="0" style="align: top">
<h:outputText value="Professor:" />
<h:panelGroup>
<p:inputText value="#{myBean.professor}" required="true" label="Prof"/>
</h:panelGroup>

<f:facet name="footer">
<p:outputPanel layout="block" style="text-align:right">
<p:commandButton value="Save" update="myTable" actionListener="#{myBean.edit}"
oncomplete="courseDialog.hide()"/>
<p:commandButton value="Cancel" onclick="courseDialog.hide()" type="button"/>
</p:outputPanel>
</f:facet>
</h:panelGrid>
</p:outputPanel>
</p:dialog>

MyBean:

@ManagedBean
@ViewScoped
public class MyBean {

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

private String professor;

public StudentCourse getSelectedStudentCourse() {
return selectedStudentCourse;
}
//The following method never gets called when required="true" for the input field "Professor" in edit dialog:
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("Marko Cicmil");
l.add(sc);
return l;
}

public void edit() {
System.out.println("In edit(): selectedStudentCourse = " + selectedStudentCourse);
}

....get/set methods for Professor
}


Thanks.

Alex
Posts: 256
Joined: 16 Dec 2010, 14:24
Location: Germany

21 May 2011, 10:00

do you have a messages component on your site?

first guess:
your link to open the dialog has no process attribute, so it will try to submit the whole form. because your dialog is in the same form, the validation fails, so your method is never called.
1. add a p:messages to your site (with autoUpdate or update it manually with your commandlink) and see if i am right
2. if i am right, you can split the datatable and the dialog in different forms, or you may work with process..
because you dont need any other data for opening the dialog a process="@this" in the commandlink should make the deal for you
PrimeFaces 3.2
Mojarra 2.0.2
Glassfish 3.0.1

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

21 May 2011, 13:41

Thanks Alex, you were right, the validation "required" was failing. If I add process="@this" to my commandLink it works fine. This also solved my other problem that I posted in another post: myBean.selectStudentCourse was getting reset to null between the methods setSelectedStudentCourse() and delete().
Thank you.

Alex
Posts: 256
Joined: 16 Dec 2010, 14:24
Location: Germany

21 May 2011, 15:44

your welcome
PrimeFaces 3.2
Mojarra 2.0.2
Glassfish 3.0.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 52 guests