How to call a action on page load in jsf
Hi all,
i am having a JSF page where i want to display the records from the datatable. I have a method in bean which call database and gets the list of records. If i call this method from a link (action on this link) present on this page i can display the records on this page.
But i want to display these records at the time of page load only. How we can do this? How to call a action at the time of page load?
Thanks in adv.
# 2
If i am calling the database class and get the list in constructor only i am able to display list in the datatable on page load. This works fine. But the requirment is that if there are no records in the list display a error page with message-No records found! . But how i can navigate from the constructor to error page?
Like-
class MyBeam{
MyBean{
private List requestVOList = null;
MyDao dao = new MyDao() //for fetching list from DB
List records = dao.getList() //get list from dao class
if(records==null)
{
//Navigate to error page. How to do this navigation here?
}
else
{
requestVOList = records;
}
//setter/getters for requestVOList
}
}
# 4
I tried to redirect to errorpage but it is throwing below exception-
[/ErrorPage.jsp]: Initialization successful.
Could not invoke the service() method on servlet /Pages/ErrorPage.jsp. Exception thrown : java.lang.NullPointerException
but there is no problem with ErrorPage.jsp when i am navigating to it from a action (like doing same thing on click of the button, and if no records found display error page. This time it is perfectly displaying the same error page), but if i am calling it from the constructor it is thowing above exception.
What might be the prob?