5

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
karolkpl
  • 2,189
  • 10
  • 39
  • 60

1 Answers1

1

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Yes, it's session scoped and should be, since it holds user preferences. I just want to set bean attribute only when param contains this attribute, otherwise NULL. My idea was to use preRenderView listener and manually check this param and set null. – karolkpl May 12 '12 at 18:40