5 Replies Latest reply on Aug 6, 2009 5:50 AM by Nick Belaevski

    applets and ajax do not mix?

    Mike Hanafey Newbie

      I have applets on a page that also does AJAX updates. Even though the AJAX update does not involve the part of the page with the applet, on every AJAX update the applet is destroyed and recreated.

      Is there a way to leave the applet alone in the face of AJAX updates?

        • 1. Re: applets and ajax do not mix?
          Ilya Shaikovsky Master

          reREnder not the part of the page with applet but just concrete components.

          • 2. Re: applets and ajax do not mix?
            Mike Hanafey Newbie

            Seeming silly question with a straight forward simple answer, but reality is a bit more twisted and devious.

            The issue was traced to <h:panelGroup> where the layout attribute is not specified (or specified as something other than "block"). In the test case below the panelGroup element is not rendered as a "div" because of the "layout" attribute. As a consequence each time the "cba2" AJAX request occurs the applet is destroyed and restarted.

            If the single change is made where the panelGroup is layout="block" the applet is *NOT* destroyed and restarted.

            The issue has impact beyond applets. With panelGroup JSF elements rendered as html span elements on AJAX updates a scrolling page ends up always reverting to the top of the display. It is almost like a non-AJAX update. Very strange, but I'm sure there is a good explanation...

            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml"
             xmlns:ui="http://java.sun.com/jsf/facelets"
             xmlns:h="http://java.sun.com/jsf/html"
             xmlns:f="http://java.sun.com/jsf/core"
             xmlns:rich="http://richfaces.org/rich"
             xmlns:a4j="http://richfaces.org/a4j">
            
            <head>
             <link rel="stylesheet" type="text/css" href="../CSS/common.css"/>
            </head>
            
            <ui:composition template="/templates/main.xhtml">
            <ui:define name="title">LT:TestingErrors</ui:define>
            <ui:define name="body">
             <div class="C-pageHeading">Error Handler Testing</div>
             <h:panelGroup id="pg" layout="not-block">
             <h:form id="f">
             <fieldset>
             <legend>Failing Actions</legend>
             <table>
             <tr>
             <td>
             <a4j:commandButton id="cba2" value="Ajax user error no traceback" reRender="f"
             actionListener="#{errors.actionListenerUserErrorNoTraceback}"/>
             </td>
             </tr>
            
             </table>
             </fieldset>
             </h:form>
             </h:panelGroup>
            
             <h:panelGroup id="foobar">
             <applet
             id="foobarApplet"
             width="100%" height="200" codebase="/MAVEN"
             code="genomix.app.utility.StdGeneticMapApplet"
             archive="
             gx/com/jgoodies/forms/1.2.1/forms-1.2.1.jar,
             gx-snapshot/genomix/legacy/GxLgStdGeneticMapApplet/1.0-SNAPSHOT/GxLgStdGeneticMapApplet-1.0-SNAPSHOT.jar,
             gx-snapshot/genomix/legacy/GxLgDB/1.0-SNAPSHOT/GxLgDB-1.0-SNAPSHOT.jar,
             gx-snapshot/genomix/legacy/GxLgGeneticMap/1.0-SNAPSHOT/GxLgGeneticMap-1.0-SNAPSHOT.jar,
             gx-snapshot/genomix/legacy/GxLgGraphics/1.0-SNAPSHOT/GxLgGraphics-1.0-SNAPSHOT.jar,
             gx-snapshot/genomix/legacy/GxLgSwing/1.0-SNAPSHOT/GxLgSwing-1.0-SNAPSHOT.jar,
             gx-snapshot/genomix/legacy/GxLgUtil/1.0-SNAPSHOT/GxLgUtil-1.0-SNAPSHOT.jar,
             gx/jal/jal/1.0/jal-1.0-double.jar,
             gx/jal/jal/1.0/jal-1.0-int.jar">
             <param name="baseUrl" value="/lt/WS"/>
             <param name="map" value="IBM2Plus"/>
             <param name="marker" value="CSU454(GST)"/>
             <param name="delta" value="10.0"/>
             </applet>
             </h:panelGroup>
            
            </ui:define>
            </ui:composition>
            </html>


            • 3. Re: applets and ajax do not mix?
              Nick Belaevski Master

              Hi,

              Yes, FF shows exactly such behavior. It doesn't like non-inline elements inside inline (see W3C specs for more) - many symptoms were collected by community - slowdowns, unwanted scrolls, broken DOM structure... Just do no do that.

              • 4. Re: applets and ajax do not mix?
                Mike Hanafey Newbie

                It seems like a mistake that by default panelGroup is not block level, especially when it is used so often for conditional rendering.

                Could RichFaces provide a conditional rendering component when the condition would only need to be specified once, with one of two different blocks getting rendered based on true or false. Or even a switch case structure like rich tree nodes. This would eliminate non-structured looking views with:

                <h:panelGroup rendered="#{some EL expresssion}">
                ...
                </h:panelGroup>
                <h:panelGroup rendered="#{not some EL expresssion}">
                ...
                </h:panelGroup>
                


                • 5. Re: applets and ajax do not mix?
                  Nick Belaevski Master

                  You can easily create such component using Facelets.