Tiny
Tiny

Reputation: 27899

f:setPropertyActionListener inside p:commandLink doesn't set the property value to the target request scoped bean

I'm trying to set a property value to a target bean using <f:setPropertyActionListener> inside <p:commandLink> as follows.

<h:form id="form" prependId="true">
    <p:panel id="dataPanel" closable="false" toggleOrientation="horizontal" toggleable="true" style="border: none; text-align: center;">
        <p:dataGrid id="dataGrid" value="#{productDetailsManagedBean}" var="row" rowIndexVar="rowIndex" rows="4" first="0" columns="1" paginator="true" paginatorAlwaysVisible="false" pageLinks="10" lazy="true" rowsPerPageTemplate="5,10,15">

            <p:commandLink process="@this">
                <h:outputText styleClass="ui-icon ui-icon-search" style="margin:0 auto;" />
                <!--row.subCatName is correctly retrieved here.-->
                <f:setPropertyActionListener value="#{row.subCatName}" target="#{productDetailsManagedBean.subCatName}" />
            </p:commandLink>

        </p:dataGrid>
    </p:panel>
</h:form>

The corresponding JSF managed bean is as follows.

@ManagedBean
@RequestScoped
public final class ProductDetailsManagedBean extends LazyDataModel<SubCategory>
{
    public ProductDetailsManagedBean() {}

    @EJB
    private final ProductDetailsBeanLocal productService=null;
    private String subCatName;

    public String getSubCatName() {
        return subCatName;
    }

    public void setSubCatName(String subCatName) {
        System.out.println("setSubCatName() called. : "+subCatName); //Never invoked.
        this.subCatName = subCatName;
    }

    //The following methods are not needed to be reviewed.

    @Override
    public List<SubCategory> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters)
    {
        int rowCount = productService.rowCount().intValue();
        setRowCount(rowCount);
        return productService.getList(first, pageSize);
    }
}

When <p:commandLink> is clicked, the corresponding setter method in the bean setSubCatName(String subCatName) is expected to be invoked but this method is never invoked and consequently the bean property subCatName is never set to a value.

What am I overlooking here?

I'm using Mojarra 2.2.5 and PrimeFaces 4.0.

The process attribute of <p:commandLink> is already set to @this. I have already tried setting prependId of <h:form> to false but that did not make a difference either.


EDIT:

This works, when the scope of the managed bean is changed from @RequestScoped to @ViewScoped. This should work in @RequestScoped beans too. What wrong am I doing here? Is this the expected behaviour?

Upvotes: 3

Views: 5162

Answers (1)

Tiny
Tiny

Reputation: 27899

This indeed requires a scope higher than the request scope for it to work (in this case, at least a view scoped bean is required). Please see this answer.

Upvotes: 2

Related Questions