0 Replies Latest reply on Dec 13, 2007 5:43 AM by Alan

    Custom Component - ajax4jsf problems?

    Alan Newbie

      Hi

      I am developing (refactoring ;) ) a component based in tomahawk sandbox imageLoop. While developing, I was having problem with page loading two times (so losing some parameters).

      encodeEnd in component (It is just for output):

      writer.startElement(HTML.DIV_ELEM, uiComponent);
      writer.writeAttribute(HTML.ID_ATTR, clientId, null);
      writer.writeAttribute(HTML.STYLE_ATTR,
       "position:relative;" +
       "width:" + width + "px;" +
       "height:" + height + "px", null);
      
      //IMAGE CREATION 1
      writer.startElement(HTML.IMG_ELEM, uiComponent);
      writer.writeAttribute(HTML.ID_ATTR, clientIdImage1, null);
      writer.writeAttribute(HTML.SRC_ATTR, "", null);
      writer.writeAttribute(HTML.STYLE_ATTR,imageLoop.getImageStyle(),null);
      writer.endElement(HTML.IMG_ELEM);
      
      //IMAGE CREATION 2
      writer.startElement(HTML.IMG_ELEM, uiComponent);
      writer.writeAttribute(HTML.ID_ATTR, clientIdImage2, null);
      writer.writeAttribute(HTML.SRC_ATTR, "", null);
      writer.writeAttribute(HTML.STYLE_ATTR,imageLoop.getImageStyle(),null);
      writer.endElement(HTML.IMG_ELEM);
      
      //Javascript
      writer.startElement(HTML.SCRIPT_ELEM, uiComponent);
      writer.writeAttribute(HTML.SCRIPT_LANGUAGE_ATTR, HTML.SCRIPT_LANGUAGE_JAVASCRIPT, null);
      writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
      String jsImageArray = getJavascriptImageArray(facesContext, uiComponent);
      writer.writeText("new ImageLoop('" + clientId + "', " +
       jsImageArray + ", " + delay + ", " + minDelay + ", "
       + maxDelay + ", "+ transitionTime + ")", null);
      writer.endElement(HTML.SCRIPT_ELEM);
      
      writer.endElement(HTML.DIV_ELEM);
      


      When I submit the form using this component, it looks that the page is rendered twice.
      If I remove the creation of the two IMAGE Tags ( writer.startElement(HTML.IMG_ELEM, uiComponent);, everything works.

      "Double page rendered" happens only when I use ajax4jsf (in this case a4j:region).

      I was able to fix the component moving the img creation to javascript, but my question is if that is a expected behavior of ajax4jsf, and if so, there is any "guideline" to write compatible components?


      PS: I am using version 3.1.2 GA and a NEWBIE