We need to call a action method while invoking the first page of the application. For example, the first page is index.jsp, when we are directly calling this page the action method is not called. To achieve that, we have written another page where it uses java script to click on the button and call the action method, that navigates to the index.jsp.
I feel that there should be proper way in JSF to achieve this task. What is the bet way to do that? I have told the team that we can call the action method in the constructor while loading the page. Is it the correct way? What are the possible solutions?
Just do the job in
@PostConstructmethod of an application scoped bean which is iseagerly constructed or which is at least bound to the page.Alternatively, if JSF (read: the
FacesContext) has no relevant role in the actual job, you can also use aServletContextListener.If you’re not on Servlet 3.0 yet, register it in
web.xmlas follows.See also: