I have the following XHTML page.
<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:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Test</title>
</h:head>
<f:metadata>
<f:viewParam name="id" value="#{testManagedBean.id}" maxlength="20"/>
</f:metadata>
<h:body>
<h:form id="form" prependId="true">
</h:form>
</h:body>
</html>
The managed bean corresponds to the above JSF page.
@ManagedBean
@ViewScoped
public final class TestManagedBean implements Serializable
{
private static final long serialVersionUID = 1L;
private Long id;
@PostConstruct
private void init() {
System.out.println("id = "+id);
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
I'm passing id
as a query-string parameter using the URL - https://localhost:8181/Project-war/admin_side/Test.jsf?id=1
.
Trying to display id
in the init()
method is always null
.
This is a demonstration. In reality, <f:viewParam>
is actually put inside <ui:define name="metaData">
and on the master template <ui:insert name="metaData"/>
is defined.
What am I overlooking here?
I have several times passed such parameters and converted to a JPA entity using appropriate converters but I don't know why a scalar value is not being set to a property of a managed bean. I have tried changing the type of id
to String but that also did not help either (nor @ManagedProperty(value="#{id}")
worked).