Skip to main content

f:viewParam is not working

No replies
z3r9
Offline
Joined: 2013-10-30
Points: 0

I am using JSF 2.2 on GlassFish 4.

I have this backing bean:

mport javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import java.io.Serializable;

@ManagedBean(name="testMB")
@RequestScoped
public class TestMB implements Serializable {

    public long id;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }
}

And this view test.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:h="http://xmlns.jcp.org/jsf/html">

<f:metadata>
    <f:viewParam name="id" value="#{testMB.id}"/>
</f:metadata>

<h:body>
    <h:inputText value="#{testMB.id}" />
</h:body>
</html>

Maven dependencies for JSF:

<dependency>
    <groupId>javax.faces</groupId>
    <artifactId>javax.faces-api</artifactId>
    <version>2.2</version>
</dependency>

When I open /test.html?id=123, then the ID shows up as 0 instead of 123. Why didn't do its job?