Set f:viewParam property to null when there is no parameter in URL
-
07-06-2021 - |
Question
Let's assume we got simple page that accepts one parameter:
<f:viewParam name="name" value="#{bean.name}"/>
When user goes to http://localhost/myapp/?name=Joe
, then #{bean.name}
is set to Joe
.
Then if user goes to http://localhost/myapp/
or http://localhost/myapp/?something=Else
, then #{bean.name}
is still set to Joe
, but I want it to be null
. How this can be done?
Solution
Use the right managed bean scope for the data it holds. You've apparently put it in the session scope. Put the bean holding the parameter in the request or view scope instead of session scope and when using view scope, make sure that you navigate by a normal link or by a post-redirect-get when performing an action.
See also:
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow