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

Hi,

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_">
      //<![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.

--
Your thoughts?


Herzliche Grüße - Best Regards,

Michael Müller
Brühl, Germany
blog.mueller-bruehl.de
it-rezension.de
@muellermi


Read my books
  "Web Development with Java and JSF" (available for short time only): https://leanpub.com/jsf
  "Practical JSF in Java EE 8" (from 2018): http://www.apress.com/us/book/9781484230299
  "Java Lambdas and Parallel Streams": http://www.apress.com/de/book/9781484224861
  "Visitors" a photographic image book: https://leanpub.com/visitors



Back to the top