1

We are JSF2 in weblogic10.3.7.

We have requirement to make auto trigger the ajax call after the page load is completed.

Probably this can be triggered from javascript document.ready function.

Any better ways ?

Thanks

user684434
  • 1,165
  • 2
  • 19
  • 39

2 Answers2

0

Take a look at PrimeFaces's RemoteCommand. You can call this RemoteCommand in your document.ready function to execute some bean method.

Dedy Chaidir
  • 767
  • 6
  • 15
Mr.J4mes
  • 9,168
  • 9
  • 48
  • 90
0

Try following code which does not include any external library.

xhtml code:

<script type="text/javascript">
        var startCalls=false;
        $(document).ready(function (){
            clickButton();
            startCalls=true;            
        })
        function clickButton(){
            document.getElementById('btn_test').click();
        }
    </script>
    <h:commandButton id="btn_test" value="Test"
                     actionListener="#{testBean.increaseCount}"
                     style="display: none">
        <f:ajax execute="btn_test" render="pnl_update_area"/>

    </h:commandButton>
    <h:panelGroup id="pnl_update_area">
        This is called #{testBean.clickCount} times
        <script type="text/javascript">
            if(startCalls){

                setTimeout('clickButton()',200);                
            }
        </script>
    </h:panelGroup>

JSF Code:

Integer clickCount=1;

public Integer getClickCount() {
    return clickCount;
}

public void setClickCount(Integer clickCount) {
    this.clickCount = clickCount;
}

public void increaseCount(ActionEvent event) {
    clickCount++;
}
Jitesh
  • 1,384
  • 10
  • 20