f: param no funciona con p: commandLink o h: commandLink en la cadena de consulta

f:param funciona muy bien conh:link, pero no conp:commandLink oh:commandLink.

Por ejemplo, tengo dos páginas.test_first.xhtml ytest_second.xhtml, y un frijol java de respaldoTestBean.java.

Empiezo a corrertest_first.xhtml.

Si hago cliclink1, el cual es unh:link, la página se redireccionará atest_second.xhtml. Con la ayuda def:param, la barra de direcciones del navegador mostrará.../test_second.xhtml?id=1. En esa pagina,testBean.userId se imprime

Si hago cliclink2 olink3, la página redirige atest_second.xhtml. Sin embargo, la barra de direcciones solo muestra.../test_second.xhtml, no hay?id=#! YtestBean.userId No se imprime en esa página.

Como puedo hacercommandLink trabajar conf:param? A veces quiero que el enlace no redirija a otra página, sino que llame a algunos métodos de bean en función de los datos.

test_first.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">
<h:head/>
<h:body>
<h:form>
    <h:link value="link1" outcome="test_second" >
        <f:param name="id" value="1"/>
    </h:link>
    <br/><br/>
    <h:commandLink value="link2" action="test_second?faces-redirect=true" >
        <f:param name="id" value="2" />
    </h:commandLink>
    <br/><br/>
    <p:commandLink value="link3" action="test_second?faces-redirect=true">
        <f:param name="id" value="3" />
    </p:commandLink>
    <br/><br/>
</h:form>
</h:body>
</html>

test_second.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">
<f:metadata>
    <f:viewParam name="id" value="#{testBean.userId}" />
</f:metadata>
<h:head/>
<h:body>
<h:form>
    This is the second page.
    <h:outputText value="Selected id is #{testBean.userId}" />
    <h:commandButton value="Print page id" action="#{testBean.print()}" />
</h:form>
</h:body>
</html>

TestBean.java

@ManagedBean
@SessionScoped
public class TestBean implements Serializable{
    private Integer userId;

    public void print() {
        System.out.println(userId);
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }
}

Respuestas a la pregunta(2)

Su respuesta a la pregunta