ICEfaces
  1. ICEfaces
  2. ICE-5830

New JavaScript context API for adding Component JavaScript to the DOM

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-Alpha2
    • Fix Version/s: 2.0-Beta2, 2.0.0
    • Component/s: ICE-Components
    • Labels:
      None
    • Environment:
      ICEfaces 2.0, Sparkle component platform
    • Affects:
      Documentation (User Guide, Ref. Guide, etc.)

      Description

      Currently, Sparkle components are "manually" rendering their Script tags inside a <SPAN> tag in the renderer. Since this is a very common requirement for the component, Ted suggests we consider using a bridge API to render the script in a span instead, such as JavaScriptContext, instead of rendering the JS Spans directly in the comp. renderer. \

      This may require adding APIs to support the req. of the components in terms of timing of execution of the JS, including detection of whether the component has changed. At a minimum, the rendering of the embedded SPAN tag + JS tag should be factored into a utility method.

        Issue Links

          Activity

          Hide
          Greg Dick added a comment -

          This is the pattern of HTML elements for the commandLink component.

          <div id="clientId" >
          <span id="clientId" + "_span" class="yui-button yui-link-button" >
          <span id="clientId" + "_s2" class="first-child" >
          <a id="cliendId" + "_anchor" actionListener="..." href="..." etc>
          </span>
          </span>
          <span id="clientId" + "_js">
          <script ...>
          yadda
          </script>
          </span>
          </div>

          The first two spans are necessary for the YUI toolkit to find and replace our stuff. The third span is useful to wrap the script with id so it can be replaced independent of the component.

          Show
          Greg Dick added a comment - This is the pattern of HTML elements for the commandLink component. <div id="clientId" > <span id="clientId" + "_span" class="yui-button yui-link-button" > <span id="clientId" + "_s2" class="first-child" > <a id="cliendId" + "_anchor" actionListener="..." href="..." etc> </span> </span> <span id="clientId" + "_js"> <script ...> yadda </script> </span> </div> The first two spans are necessary for the YUI toolkit to find and replace our stuff. The third span is useful to wrap the script with id so it can be replaced independent of the component.
          Hide
          Mircea Toma added a comment - - edited

          Introduced ScriptWriter utility class to eliminate component renderer boiler plate code when writing script code to be evaluated on the client.

          There are two ways to write (and eventually evaluate) JS code.

          Calling ScriptWriter.insertScript(FacesContext , UIComponent, String) allows the component renderer to write the script markup and code in one method call. This method is useful when the JS code complexity is low. For example:

          public void encodeEnd(FacesContext context, UIComponent component) throws IOException

          { .... .... ScriptWriter.insertScript(context, component, "ice.component.calendar.init();"); .... }

          The other method of writing the JS code allows writing the code gradually by streaming it directly through the response writer. This method can be used when the complexity of JS code is higher. For example:

          public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
          ....
          ScriptWriter writer = ScriptWriter.insertScript(facesContext, uiComponent);
          writer.startScript();
          writer.write("ice.yui3.slider.updateProperties('");
          writer.write(clientId);
          writer.write("', ");
          //pass through YUI slider properties
          writer.write("

          {"); writer.write("min:"); writer.write(slider.getMin()); writer.write(", "); writer.write("max:"); writer.write(slider.getMax()); writer.write(", "); writer.write("value:"); writer.write(slider.getValue()); .... .... writer.write("tabindex:"); writer.write(slider.getTabindex()); writer.write("}

          );");
          writer.endScript();
          }

          Show
          Mircea Toma added a comment - - edited Introduced ScriptWriter utility class to eliminate component renderer boiler plate code when writing script code to be evaluated on the client. There are two ways to write (and eventually evaluate) JS code. Calling ScriptWriter.insertScript(FacesContext , UIComponent, String) allows the component renderer to write the script markup and code in one method call. This method is useful when the JS code complexity is low. For example: public void encodeEnd(FacesContext context, UIComponent component) throws IOException { .... .... ScriptWriter.insertScript(context, component, "ice.component.calendar.init();"); .... } The other method of writing the JS code allows writing the code gradually by streaming it directly through the response writer. This method can be used when the complexity of JS code is higher. For example: public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException { .... ScriptWriter writer = ScriptWriter.insertScript(facesContext, uiComponent); writer.startScript(); writer.write("ice.yui3.slider.updateProperties('"); writer.write(clientId); writer.write("', "); //pass through YUI slider properties writer.write(" {"); writer.write("min:"); writer.write(slider.getMin()); writer.write(", "); writer.write("max:"); writer.write(slider.getMax()); writer.write(", "); writer.write("value:"); writer.write(slider.getValue()); .... .... writer.write("tabindex:"); writer.write(slider.getTabindex()); writer.write("} );"); writer.endScript(); }
          Hide
          Ken Fyten added a comment -

          Need to move this into the Sparkle platform (out of the std. bridge) as a new utility API. Please review and complete the move.

          Show
          Ken Fyten added a comment - Need to move this into the Sparkle platform (out of the std. bridge) as a new utility API. Please review and complete the move.
          Hide
          yip.ng added a comment -

          Done. It is now org.icefaces.component.utils.ScriptWriter.

          Show
          yip.ng added a comment - Done. It is now org.icefaces.component.utils.ScriptWriter.

            People

            • Assignee:
              yip.ng
              Reporter:
              Ken Fyten
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: