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

Suppose we get a simple page that takes one parameter:

<f:viewParam name="name" value="#{bean.name}"/> 

When the user goes to http://localhost/myapp/?name=Joe , then #{bean.name} set to Joe . Then, if the 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 can I do that?

+4
source share
1 answer

Use the correct managed bean for the data that it stores. You obviously placed it in the session area. Place the bean while holding the parameter in the request or presentation area, not the session area, and when using the browse area, make sure you follow the regular link or post-redirect-get when performing the action.

See also:

+1
source

Source: https://habr.com/ru/post/1411981/


All Articles