2

I am using Primefaces and I have a problem that the setPropertyActionListener isn't fired and thus isn't setting a property of a view scoped managed bean.

My view:

<p:column>
    <p:commandLink value="Supprimer" oncomplete="confirmation.show()"  >
        <f:setPropertyActionListener value="#{car}" target="#{typeMB.selectedType}" />  
    </p:commandLink>
</p:column>

The managed-bean has the selectedType property for which there is both a getter and a setter.

My managed bean:

@ManagedBean(name="typeMB")
@ViewScoped
public class TypeManagedBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private Type newtype;  
    private Type selectedType;

    @ManagedProperty(value="#{TypeDao}")
    GenericDao<Type> typeDAO;

    public TypeManagedBean(){
        newtype = new Type();
    }

    public List<Type> getList_types() {     
        return typeDAO.readAll();
    }

    public void setTypeDAO(GenericDao<Type> typeDAO) {
        this.typeDAO = typeDAO;
    }

    public GenericDao<Type> getTypeDAO() {
        return typeDAO;
    }

    public Type getNewtype() {
        return newtype;
    }

    public void setNewtype(Type newtype) {
        this.newtype = newtype;
    }       

    public Type getSelectedType() {
        if(selectedType != null)
        System.out.println("get : le selected type : "+selectedType.getLibelle());
        return selectedType;
    }

    public void setSelectedType(Type selectedType) {        
        this.selectedType = selectedType;
        System.out.println("set le selected type : "+selectedType.getLibelle());
    }

}

What can I do to achieve what I want?

skuntsel
  • 11,346
  • 11
  • 41
  • 64
simonTifo
  • 297
  • 3
  • 11
  • 28

2 Answers2

4

According to the Primefaces (3.5) user's guide, section on <p:commandLink>, and the statement made by Primefaces lead on this forum, the default value of process attribute is @all, meaning that the whole page will be submitted. So, there might be some validation errors from this submission, preventing listener methods to be called. Otherwise, it should work as expected with the code you posted.

A good test for the abovementioned supposition is to put process="@this" attribute. Because the 'actions associated with the link to be executed, it is mandatory to partially submit the link itself', as is perfectly explained by BalusC in What is the function of this exactly, we need to add the attribute to do the test.

Another thing to be checked is that your command components belong to a form and that your view does not contain nested forms anywhere.

Community
  • 1
  • 1
skuntsel
  • 11,346
  • 11
  • 41
  • 64
1

The following code is working:

The Managed bean:

package app.so.dev.web.controller;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import app.so.dev.web.model.Student;

@ManagedBean(name = "so15344819")
@ViewScoped
public class SO15344819 implements Serializable {

    private static final long serialVersionUID = 6686378446131077581L;
    private List<Student> students;
    private Student selectedStudent;

    @PostConstruct
    public void init() {
        students = new ArrayList<Student>();
        students.add(new Student("Student 1"));
        students.add(new Student("Student 2"));
    }

    public List<Student> getStudents() {
        return students;
    }

    public void setStudents(List<Student> students) {
        this.students = students;
    }

    public Student getSelectedStudent() {
        return selectedStudent;
    }

    public void setSelectedStudent(Student selectedStudent) {
        this.selectedStudent = selectedStudent;
    }
}

And the xhtml:

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" template="/WEB-INF/templates/globalTemplate.xhtml">

    <ui:define name="title">15344819</ui:define>
    <ui:define name="content">
        <p:growl id="growl" showDetail="true" />

        <h:form id="form">
            <p:dataTable id="students" value="#{so15344819.students}" var="student">
                <p:column>
                        <p:commandButton id="selectButton" update=":form:display" oncomplete="studentDialog.show()" icon="ui-icon-search" title="View">
                           <f:setPropertyActionListener value="#{student}" target="#{so15344819.selectedStudent}" />
                       </p:commandButton>
                   </p:column>
            </p:dataTable>

            <p:dialog header="Student Detail" widgetVar="studentDialog" resizable="false" id="studentDlg"
                            showEffect="fade" hideEffect="explode" modal="true">

                    <h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">

                        <h:outputText value="Name:" />
                        <h:outputText value="#{so15344819.selectedStudent.name}" style="font-weight:bold"/>                                               

                    </h:panelGrid>

                </p:dialog>
        </h:form>
    </ui:define>

</ui:composition>

Environment:

  • JSF Mojarra 2.1.7
  • Primefaces 3.4.2
  • JBoss AS 7.1

Primefaces Showcase.

Tapas Bose
  • 25,780
  • 71
  • 202
  • 317