Problema com f:param

Boa tarde…

Estou com problema ao usar a tag f:param. Na hora de retirar o valor [e retornado null.

Segue abaixo os códigos:
[b]
[color=red]JSP:[/color]
<h:commandButton image="/imagens/acessorios.jpg" action="#{rpBean.paginaAcessorios}">
<f:param name=“categoria” value=“A” />
</h:commandButton>

[color=red]BEAN:[/color]

public String paginaAcessorios(){

String valCategoria = getParametro("categoria");
listaItem = consultas.returnAllProducts(valCategoria);


return "acessorios";

}

private String getParametro(String nomeParametro) {

nomeParametro = (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(nomeParametro);


return nomeParametro;

}[/b]

nomeParametro não está recendo o valor, alguém poderia me dá uma luz?

desde já agradeço!

Olá, seu não me engano a tag <f:param> não funciona com commandButton, somente com commandLink and outputLink.

Para pasar parametro com commandButton vc pode usar isso:

<h:form>

    <h:commandButton value="Press here" action="#{myBean.action}">
        <f:setPropertyActionListener target="#{myBean.propertyName1}" value="propertyValue1" />
        <f:setPropertyActionListener target="#{myBean.propertyName2}" value="propertyValue2" />
    </h:commandButton>
</h:form>

E no ManagedBean

package mypackage;


public class MyBean {

   
    private String propertyName1; 
    private String propertyName2; 

   

    public void action() {
        System.out.println("propertyName1: " + propertyName1);
        System.out.println("propertyName2: " + propertyName2);
    }

  

    public void setPropertyName1(String propertyName1) {
        this.propertyName1 = propertyName1;
    }

    public void setPropertyName2(String propertyName2) {
        this.propertyName2 = propertyName2;
    }

}

Ou ainda por eventos como actionListener, assim:

<h:form>
    <h:commandLink value="Click here" actionListener="#{myBean.action}">
        <f:attribute name="attributeName1" value="attributeValue1" />
        <f:attribute name="attributeName2" value="attributeValue2" />
    </h:commandLink>

    <h:commandButton value="Press here" actionListener="#{myBean.action}">
        <f:attribute name="attributeName1" value="attributeValue1" />
        <f:attribute name="attributeName2" value="attributeValue2" />
    </h:commandButton>
</h:form>

E no ManagedBean


package mypackage;

import javax.faces.event.ActionEvent;

import net.balusc.util.FacesUtil;

public class MyBean {

   
    public void action(ActionEvent event) {
        String attributeName1 = FacesUtil.getActionAttribute(event, "attributeName1");
        String attributeName2 = FacesUtil.getActionAttribute(event, "attributeName2");

        System.out.println("attributeName1: " + attributeName1);
        System.out.println("attributeName1: " + attributeName1);
    }

}
package net.balusc.util;

import javax.faces.event.ActionEvent;

public class FacesUtil {

    // Getters -----------------------------------------------------------------------------------

    public static String getActionAttribute(ActionEvent event, String name) {
        return (String) event.getComponent().getAttributes().get(name);
    }

}

Testa ai!, qualquer duvida pergunte!

Att

vaaleu cara, vou testar! :smiley: