Invoke JSF managed bean action on page load

前端 未结 4 2344
别跟我提以往
别跟我提以往 2020-11-22 13:16

Is there a way to execute a JSF managed bean action when a page is loaded?

If that\'s relevant, I\'m currently using JSF 1.2.

4条回答
  •  没有蜡笔的小新
    2020-11-22 13:42

    Another easy way is to use fire the method before the view is rendered. This is better than postConstruct because for sessionScope, postConstruct will fire only once every session. This will fire every time the page is loaded. This is ofcourse only for JSF 2.0 and not for JSF 1.2.

    This is how to do it -

    
          
              
          
    
    

    And in the myController.java

     public void onPageLoad(){
        // Do something
     }
    

    EDIT - Though this is not a solution for the question on this page, I add this just for people using higher versions of JSF.

    JSF 2.2 has a new feature which performs this task using viewAction.

    
        
    
    

提交回复
热议问题