Skip to main content



      Home
Home » Eclipse Projects » Eclipse Mojarra » support non JavaScript usage of websocket(support non JavaScript usage of websocket)
support non JavaScript usage of websocket [message #1783785] Sat, 17 March 2018 05:14
Eclipse UserFriend
Although a JSF user might use the JavaScript API to start an ajax request, most simply use the f:ajax tag. JSF tags usually hide away HTML and/or JavaScript stuff, but websocket.

Consider this page excerpt of a definition:

<f:websocket channel="events" onmessage="eventListener" />

<script type="text/javascript">
//<![CDATA[
function eventListener(message, channel, event) {
var element = document.getElementById("activity");
element.innerHTML = message;
}
//]]>
</script>

<h1>
<h:outputLabel value="Last activity: "/>
<h:outputText id="activity" value=""/>
</h1>

The user needs some JS woodoo to handle the message he received from the server.

I suggest to optionally hide JS by a special "target" attribute:

<f:websocket channel="events" target="activity" />

<h1>
<h:outputLabel value="Last activity: "/>
<h:outputText id="activity" value=""/>
</h1>

If target is declared, than then inner html of the referenced component will be replaced by the message. If target is declared, than the user might omit "onmessage". It will be allowed to use both.

As an additional sugesstion, a "max" attribute can be added to "target"

<f:websocket channel="events" target="activity" max="10"/>

If max is not defined, it is treated as one. Max is used to control how many messages will be added to the target element. If just on, the inner html will be replaced. If > 1 than the message will be added. If > max then the first message will be removed. This is useful for list elements or textareas. In case of text areas, the message will be added as a new line, removing lines in front if there are more than max.
Goto Forum:
  


Current Time: Tue Jul 08 22:34:37 EDT 2025

Powered by FUDForum. Page generated in 0.06889 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top