What is the correct (best) way to set a managed bean’s property from a request’s parameter?
The URL for my JSF page looks something like this:
https://eample.com/app/faces/page.xhtml?ts=2012-01-05T10:00:00.000
I have found that I can read the parameter using the following:
<h:outputText value="#{param['ts']}" />
But what I really need to do is set my bean’s property from this value. So what
is the best JSF way code this so I get something which results Java code like this:
myBean.setTimestamp(request.getParameter("timestamp"));
Many thanks
Assuming a JSF managed bean with request scope, inject it as a managed property:
If the bean is in a broader scope, you will need to look it up programmatically:
If you are using CDI beans, you will need to consider other options (see here for one approach.)