Property action listener is not called when attached to Primefaces' command link

simonTifo picture simonTifo · Mar 11, 2013 · Viewed 9.4k times · Source

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?

Answer

skuntsel picture skuntsel · Mar 11, 2013

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.