Keep WebSocket connection in current page alive when command button action is invoked

StackOverflow https://stackoverflow.com/questions/21303796

  •  01-10-2022
  •  | 
  •  

سؤال

I've created a WebSocket in a JSF application. It works fine, but when I invoke a JSF bean action using <h:commandButton action="#{bean.something}">, then it restarts the WebSocket connection.

Is there any way to implement this 2 types of connections without interrupting each other?

هل كانت مفيدة؟

المحلول

The JSF <h:commandButton> component generates a HTML <input type="submit"> element which performs by default a synchronous form submit which has as consequence a full page reload and thus a full change of the HTML document.

This is fully expected behavior. You want an asynchronous (ajax) form submit instead. This way the HTML document remains the same. In order to achieve that, just nest a <f:ajax> inside the <h:commandButton>.

<h:commandButton ...>
    <f:ajax execute="@form" render="@form" />
</h:commandButton>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top