Reputation: 4615
I am just getting started using JavaServer Faces and am having a bit of trouble wrapping my mind around how parts of the navigation work.
What I want to do is have my application hit a java method before loading the welcome page in order for that data to be available on the welcome page. I know how to do this on other pages by creating using the following:
<h:commandLink action="#{myController.methodName}" />
And then having that method return an outcome that would then go to the page that I want. However, I am unsure how to do this for the welcome page.
Upvotes: 1
Views: 407
Reputation: 1108722
Just put the desired code in the constructor of the managed bean class associated with the page.
public Bean() {
// Do your stuff here.
}
Alternatively, you can declare a bean method with the @PostConstruct
annotation. Such a method will be executed directly after construction and initialization/setting of all managed properties.
@PostConstruct
public void init() {
// Do your stuff here.
}
This is more useful if the action depends on request parameters and/or another beans.
Upvotes: 1