1 Reply Latest reply on Jan 18, 2008 3:15 PM by wbossons

    AjaxContext Usage

    wbossons

      Hello,

      I'm using Ajax4Jsf in a JEE5 application (JSF is Sun RI 1.2, Shale Tiles, Ajax4Jsf 1.1.2), and running into an issue with the complete page rendering when I only want the ajax region to rerender. My code works in a non-tiled environment, so the basic usage of the a4j tags is correct.

      The issue appears to be that the application is trying to run through the TilesViewHandler. I suspect that I have to bypass this in some way. I'm trying to use AjaxContext with renderAjaxRegion, but when I do this, I have javascript errors with A4j is not defined, log is not ....

      I'm probably not understanding the API -- there are almost no explanations and I understand that this is the challenge in development -- to write code and documentation.

      I wrote a phase listener and tried to use:

      AjaxContext ajaxcontext = AjaxContext.getCurrentInstance(context);
      UIComponent component = context.getViewRoot().findComponent(ajaxcontext.getSubmittedRegionClientId(context));
      ajaxcontext.renderAjaxRegion(context, component, false);

      The tiles view handler does not get hit, but neither does Ajax work at this point.

      Does anyone know how to render the response and bypass the tiles view handler and would you please share it with me?

      Thanks so much,

      Wendy

        • 1. Re: AjaxContext Usage
          wbossons

          I'll answer my own question. I hope it helps other developers/users. The answer is yes. It is possible to use Tiles with Ajax4Jsf.

          I wrote a PhaseListener that checks to see if this is an ajax request. I have a specific scenario that I'm addressing, so I'm using a request scoped attribute that tells me when it is Ajax. Then during the render_response phase, in the beforePhase method, I call the AjaxContext to render the page.

          FacesContext context = pe.getFacesContext();
          AjaxContext ajaxcontext = AjaxContext.getCurrentInstance(context);
          //Render the response
          try {
          ajaxcontext.renderSubmittedAjaxRegion(context);

          ...................
          that does it -- renders the page, bypassing the tiles view handler. One other note: if your site is XHTML Transitional, reset the content_type in the afterPhase of render_response to text/html. Otherwise, the AjaxFilter always sets the content type to text/xml, regardless of the forceparser parameter setting. This will break any pages that do not adhere to xhtml strict.

          ..\Wendy