What is the difference between defining View Params like this:
Sets the value during update model values phase only (since it extends UIInput).
The set value is not available during @PostConstruct, so you need an additional
for that instead.
Allows for nested
Can be included as GET query string using includeViewParams
attribute of includeViewParams=true
request parameter in any URL.
Can be used on a @RequestScoped bean, but it requires the bean to be @ViewScoped if you want the view parameters to survive any validation failures caused by forms enclosed in the view, otherwise you need to manually retain all request parameters for the subsequent requests by
in the command components.
Example:
with
private User user;
and an @FacesConverter("userConverter"). Invoking page by http://example.com/context/user.xhtml?id=123 will pass the id
parameter through the converter and set the User
object as a bean property.
Sets the value immediately after bean's construction.
Set value is available during @PostConstruct which allows easy initialization/preloading of other properties based on the set value.
Doesn't allow for declarative conversion/validation in view.
Managed property of #{param}
is not allowed on beans with a broader scope than request scope, so the bean is required to be @RequestScoped.
If you rely a managed property of #{param}
being present in the subsequent POST requests, then you need to include it as
in the UICommand
components.
Example:
@ManagedProperty("#{param.id}")
private Long id;
private User user;
@EJB
private UserService userService;
@PostConstruct
public void init() {
user = userService.find(id);
}
But you have to manage validation yourself whenever user
is null
by fiddling with FacesContext#addMessage() or something.
You can use them both when both @PostConstruct and includeViewParams
are mandatory. You only won't be able to apply fine-grained conversion/validation anymore.