3 Replies Latest reply on Feb 18, 2009 7:37 PM by Alexander Smirnov

    Javascript included for non-rendered components

    Toby Ambrose Newbie

      Forgive me if this has been covered. I wasn't able to find the issue after extensive searching.

      I have a JSF page which contains both a standard h:dataTable and a rich:dataTable plus a rich:modalPanel.

      The standard data table is only rendered for a mobile browser request and the richfaces components are rendered only if the request comes from a desktop browser.

      The problem - the Javascript for the rich:dataTable and rich:modelPanel is included in the mobile browser case (when those controls are not rendered). I've confirmed by removing those tags from the page and redeploying the page 274K lighter without them.

      I even tried adding the following to the web.xml file just in case.

      <context-param>
       <param-name>org.richfaces.LoadScriptStrategy</param-name>
       <param-value>DEFAULT</param-value>
      </context-param>
      


      I did find a post regarding a portlet adapter but I'm not using anything close.

        • 1. Re: Javascript included for non-rendered components
          Nick Belaevski Master

          Hello,

          Yes, that's a type of "feature". As a workaround you can use c:if tags that won't create components if they're not necessary. Please reply if this is acceptable for you or not.

          • 2. Re: Javascript included for non-rendered components
            Toby Ambrose Newbie

            Thank you for the reply and the suggestion. I tried it and that does solve my problem.

            That does seem like a bug more than a feature though. Maybe I'm misunderstanding the intent of the render flag, but it seems to me that's the entire reason for having it - don't include this component (and any related JS or CSS) when creating output for the client request.

            Perhaps it's not the best approach to have basic HTML tables and Richfaces tables in the same xhtml page and simply toggle which one is rendered based on the user agent type. However, that seems like one of the strengths of JSF and Richfaces - keeping the markup in one page and simply toggle the content based on browser capabilities. Especially in this case where two non-rendered components increase the page weight by over 270K with Javascript. Seems that a web technology should be a little more conscious of download performance.

            Thanks again for your help!

            • 3. Re: Javascript included for non-rendered components
              Alexander Smirnov Master

              This is HTML-specific feature. Sometimes even not possible to append additional styles and scripts after page have been loaded. For example, document.write method dos not work after page loading, frameworks like jQuery requires "onload" event and so on. Since early ajax4jsf we collect all resources required by components even though component itself does not rendered.
              Really, content-depended design with a lot of conditions omit base MVC pattern. For these tasks much better to create different pages for a different agent types and switch them from one controller. In this case you can use even different render kit implementations to adopt your site design for an any type of client.