function notify() {
var json = {
'sessionId': "#{session.id}",
'cartToken': "#{socketTokenBean.token}"
};
notifyAll(JSON.stringify(json)); // Push "json" to a WebSocket channel.
}
<p:inputText value="#{bean.value}" .../>
<p:commandButton value="Submit" oncomplete="notify()" process="@this" update="..." .../>
There could be another component like <p:selectOneMenu>
in place of <p:inputText>
. Consider it as an input component holding a quantity value in a shopping basket. bean
is a session scoped managed bean holding a list of items in a shopping basket.
The oncomplete
handler of <p:commandButton>
invokes a JavaScript function which pushes a JSON message to a WebSocket channel. Obviously, if nothing is changed in <p:inputText>
, pushing a JSON message to a WebSocket channel is worth nothing - it will unnecessarily send associated clients a notification taking unnecessary processing power.
Is there a way to invoke the notify()
function here oncomplete="notify()"
, only if the value held by the given <p:inputText>
has been changed?