f:param ne fonctionne pas avec p:commandLink ou h:commandLink sur la chaîne de requête

f:param fonctionne très bien avec h:link, mais pas avec p:commandLink ou h:commandLink.

Par exemple, j'ai deux pages test_first.xhtml et test_second.xhtml, et un backing bean java TestBean.java.

- Je commencer à courir test_first.xhtml.

Si je clique sur link1, qui est un h:link, la page de redirection vers test_second.xhtml. Avec l'aide de f:param, la barre d'adresse du navigateur affiche .../test_second.xhtml?id=1. Sur cette page, testBean.userId est imprimé.

Si je clique sur link2 ou link3, la redirection de la page de test_second.xhtml. Toutefois, la barre d'adresse affiche uniquement .../test_second.xhtml, il n'y a PAS de ?id=#! Et testBean.userId ne pas publiées sur cette page.

Comment puis-je faire commandLink travailler avec f:param? Parfois, je veux le lien de ne pas rediriger vers une autre page mais de faire appel de certaines méthodes de haricot en fonction des données.

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;
    }
}
InformationsquelleAutor ethanjyx | 2013-08-21