ICEfaces
  1. ICEfaces
  2. ICE-3159

Add "nospan" attribute to ice:outputText component

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.7
    • Fix Version/s: 1.7.2
    • Component/s: Bridge, Framework
    • Labels:
      None
    • Environment:
      IE 7
    • Affects:
      Documentation (User Guide, Ref. Guide, etc.)
    • Workaround Exists:
      Yes
    • Workaround Description:
      Hide
      Do two things to your outputText:

      1) Add some text in front of the bean binding
      2) Set the visible attribute to false (so the text won't display)

      <ice:outputText escape="false"
                      value="blah #{test.script}"
                      visible="false"/>

      Adding some text in front seems to fix the problem with IE without affecting Firefox and Safari. Setting visible to false ensures that the span and contents aren't displayed. I tried using style="display:none;" directly in the component without success. It seemed that the style wasn't properly rendered out. Setting visible to false actually sets this style for you.
      Show
      Do two things to your outputText: 1) Add some text in front of the bean binding 2) Set the visible attribute to false (so the text won't display) <ice:outputText escape="false"                 value="blah #{test.script}"                 visible="false"/> Adding some text in front seems to fix the problem with IE without affecting Firefox and Safari. Setting visible to false ensures that the span and contents aren't displayed. I tried using style="display:none;" directly in the component without success. It seemed that the style wasn't properly rendered out. Setting visible to false actually sets this style for you.

      Description

      Because we don't have a component for adding scripts to pages, one technique that we've used in certain situations is to create an ice:outputText component bound to a backing bean that inserts the snippet of script dynamically. This can be especially useful in portlet situations where determining the URL of JavaScript resource can be tricky. The technique works fine in every browser that I tried except for IE 7. I've so far narrowed it down to the the following logic in the application.js file. I've added two logging statements to highlight the issue:

                  commandDispatcher.register('updates', function(element) {
                      $enumerate(element.getElementsByTagName('update')).each(function(updateElement) {
                          try {
                              var address = updateElement.getAttribute('address');
                              var update = new Ice.ElementModel.Update(updateElement);
                              
                              //Logging added
                              logger.debug('applied update.asHTML(): ' + update.asHTML());
                              
                              address.asExtendedElement().updateDOM(update);
                              
                              //Logging added
                              logger.debug('address.asElement.outerHTML : ' + address.asElement().outerHTML);
                              
                              scriptLoader.searchAndEvaluateScripts(address.asElement());
                              if (Ice.StateMon) {
                                  Ice.StateMon.checkAll();
                                  Ice.StateMon.rebuild();
                              }
                          } catch (e) {
                              logger.error('failed to insert element: ' + update.asString(), e);
                          }
                      });
                  });

      When I run my simple test application, I get the following logging output:


      Safari

      [window.QPlE#1] : applied update.asHTML(): <span class="iceOutTxt" id="j_id6:j_id7:j_id13"><script type="text/javascript" language="javascript">alert('add 1213132969669');</script></span>
      [window.QPlE#1] : address.asElement.outerHTML : <span class="iceOutTxt" id="j_id6:j_id7:j_id13"><script type="text/javascript" language="javascript">alert('add 1213132969669');</script></span>


      IE 7

      [window.ouab#1] : applied update.asHTML(): <span class="iceOutTxt" id="j_id6:j_id7:j_id13"><script type="text/javascript" language="javascript">alert('add 1213132260384');</script></span>
      [window.ouab#1] : address.asElement.outerHTML : <SPAN class=iceOutTxt id=j_id6:j_id7:j_id13></SPAN>


      It appears that, in IE7, it tries to apply the incoming update (a <span> that contains the <script> tag) but when it goes to look it up again (address.asElement()) the <script> section has been removed.

        Issue Links

          Activity

          Hide
          Deryk Sinotte added a comment -

          Attaching a test case (minus the WEB-INF/lib directory contents).

          Show
          Deryk Sinotte added a comment - Attaching a test case (minus the WEB-INF/lib directory contents).
          Hide
          Deryk Sinotte added a comment -

          Further testing showed that removing the wrapping <span> tags from around the <script> tags allowed this to work in IE 7. I'm not sure of the exact mechanism for failure here (whether IE just removes the child <script> node or whether it's some other processing that we are doing) but the answer may be to add an attribute to the ice:outputText component so that you can specify "nospan".

          Show
          Deryk Sinotte added a comment - Further testing showed that removing the wrapping <span> tags from around the <script> tags allowed this to work in IE 7. I'm not sure of the exact mechanism for failure here (whether IE just removes the child <script> node or whether it's some other processing that we are doing) but the answer may be to add an attribute to the ice:outputText component so that you can specify "nospan".
          Hide
          Deryk Sinotte added a comment -

          Changed summary of the case from:

          Cannot use ice:outputText componet to render our snippets of JavaScript in IE 7

          Show
          Deryk Sinotte added a comment - Changed summary of the case from: Cannot use ice:outputText componet to render our snippets of JavaScript in IE 7
          Hide
          Deryk Sinotte added a comment -

          Adding a potential workaround.

          Show
          Deryk Sinotte added a comment - Adding a potential workaround.
          Hide
          Deryk Sinotte added a comment -

          Updating workaround.

          Show
          Deryk Sinotte added a comment - Updating workaround.
          Hide
          Deryk Sinotte added a comment -

          Until we have a real outputScript component available, this workaround should suffice.

          Show
          Deryk Sinotte added a comment - Until we have a real outputScript component available, this workaround should suffice.
          Hide
          Ken Fyten added a comment -

          ICE-1931 contains the commit that adds the new "nospan" attribute to the ice:outputText component.

          Show
          Ken Fyten added a comment - ICE-1931 contains the commit that adds the new "nospan" attribute to the ice:outputText component.

            People

            • Assignee:
              Unassigned
              Reporter:
              Deryk Sinotte
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: