Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[mojarra-dev] Hide JS from websocket to become more JSF alike


I just entered the first topic to the eclipse Moharra forum. It's a moderated forum and thus the message did not appear yet. And mayby this list is the better place for suggestions?

This is what I posted:

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_">
      function eventListener(message, channel, event) {
        var element = document.getElementById("activity");
        element.innerHTML = message;

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

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" />

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

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.

Your thoughts?

Herzliche Grüße - Best Regards,

Michael Müller
Brühl, Germany

Read my books
  "Web Development with Java and JSF" (available for short time only):
  "Practical JSF in Java EE 8" (from 2018):
  "Java Lambdas and Parallel Streams":
  "Visitors" a photographic image book:

Back to the top