Victor Tsuchida
Victor Tsuchida

Reputation: 13

f:setPropertyActionListener not calling method

I need some help. I'm having trouble with using f:setPropertyActionListener on JSF. The problem is that the JSF is not setting any value on the target method.

Part of the xhtml code is the following:

<h:form>
    <fieldset style="width:100; margin-left: 350px; margin-top: 250px; position:absolute; border-style: none">
        <p:dataGrid var="prod" value="#{productoController.arrProductosRelevantes}" 
                    columns="5" rows="10" paginator="true">

            <p:panel style="text-align:center">  
                <h:panelGrid columns="1" style="width:100%" columnClasses="colStyle1" rowClasses="rowStyle1" >  
                    <p:graphicImage value="#{prod.imagenUrl}" style="width:100px; height:100px"/>   
                    <h:outputText value="#{prod.marca}" style="width:40px"/>  
                    <p:commandLink value="Ver" action="#{productoController.visualizarProducto()}">  
                        <f:setPropertyActionListener value="#{prod}"   
                                                     target="#{productoController.productoSeleccionado()}" />  
                    </p:commandLink>
                </h:panelGrid>  
            </p:panel>  
        </p:dataGrid>  
    </fieldset>
</h:form>

The backing bean is the following (the most relevant):

public Producto getProductoSeleccionado() {
    return productoSeleccionado;
}

public void setProductoSeleccionado(Producto productoSeleccionado) {
    if (productoSeleccionado != null) {
        this.productoSeleccionado = productoSeleccionado;
        arrComentarios = null;
        arrProductosComplementarios = null;
        arrProductosSuplementarios = null;
    }
}

public String visualizarProducto() {
    if (arrComentarios == null) {
        obtenerComentarios();
    }
    if (arrProductosComplementarios == null) {
        obtenerArrProductosComplementarios();
    }
    if (arrProductosSuplementarios == null) {
        obtenerArrProductosSuplementarios();
    }
    return "visualizarProducto.xhtml?faces-redirect=true";
}


public ArrayList<Producto> getArrProductosRelevantes() {
    return arrProductosRelevantes;
}

public void obtenerArrProductosRelevantes() {
    clienteDAO = new ClienteDAO();
    productoDAO = new ProductoDAO();
    cliente = clienteDAO.getClientePorId(Sesion.IDCLIENTE);
    arrProductosRelevantes = productoDAO.obtenerProductoRelevantesPorCliente(cliente);
}

By the way, I'm using @SessionScoped.

Any help will be appreciated, thanks.

Upvotes: 0

Views: 1665

Answers (1)

Elias Dorneles
Elias Dorneles

Reputation: 23806

The target attribute of f:setPropertyActionListener is supposed to be a property, not a method. That means, if you set target="#{productoController.productoSeleccionado}" it will call the setProductoSeleccionado(Producto prod) method in the productoController bean, passing as argument the value you set for the value attribute.

You are referring to a method productoSeleccionado() that may well not even exist in your code. So, just lose the parenthesis and you should be fine:

<f:setPropertyActionListener value="#{prod}"
               target="#{productoController.productoSeleccionado}" />

Upvotes: 1

Related Questions