jsf - Accessing query-string parameters in a post construct method in a view scoped managed bean -
i have 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 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
query-string parameter using url - https://localhost:8181/project-war/admin_side/test.jsf?id=1
.
trying display id
in init()
method null
.
this demonstration. in reality, <f:viewparam>
put inside <ui:define name="metadata">
, on master template <ui:insert name="metadata"/>
defined.
what overlooking here?
i have several times passed such parameters , converted jpa entity using appropriate converters don't know why scalar value not being set property of managed bean. have tried changing type of id
string did not either (nor @managedproperty(value="#{id}")
worked).
the value of f:viewparam
not available during @postconstruct
. use f:viewaction
instead.
Comments
Post a Comment