Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set f:viewParam property to null when there is no parameter in URL

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?

like image 496
karolkpl Avatar asked Nov 14 '22 05:11

karolkpl


1 Answers

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:

  • How to choose the right bean scope?
like image 159
BalusC Avatar answered Dec 09 '22 19:12

BalusC