Search code examples
jsfjsf-2primefaces

JSF onclick refreshes page


<h:commandButton  onclick="window.open('/page.html')" value="test" action="#{bean.myAction}"></h:commandButton>

After I click on above the browser appears to refresh the page and scroll to the top.

If I use "return false;" the action never runs.

How can I stop this from happening?


Solution

  • Not sure why you are using the "window.open('/page.html')", But if you want to open the page after the action command completes then do the following

    <h:commandButton value="test" action="#{bean.myAction}">
        <f:ajax onevent="function(data){ if(data.status === 'success') window.open('/page.html')}"/>
    </h:commandButton>