Skip to main content

ICEFaces 2.0 And JSF 2.0 Together

Posted by rogerk on May 25, 2009 at 4:40 PM PDT

JSF Ajax frameworks have been around for some time. JSF is all about
server side components that render
their state as markup to the client. JSF has a well defined lifecycle
that defines how component state
is handled on the server and when component state is rendered to the
client.  JSF Ajax frameworks can control which components are
processed on the server (known as partial processing), and which
components render themselves back to the client (known as partial
rendering) by sending Ajax requests with special parameters. 



How ICEFaces Uses JSF 2.0  To
Send Ajax Requests



The JSF 2.0 Ajax JavaScript API style="font-style: italic;">jsf.ajax.request style="font-style: italic;"> can be used to trigger Ajax
requests from an HTML event such as onclick
This function can be called from within a JavaScript function
too.  ICEFaces uses the jsf.ajax.request
function within their JavaScript library:


cellpadding="2" cellspacing="2">
style="vertical-align: top; background-color: rgb(204, 255, 255);"> 

    submitEvent = function(event, element, form) {

    ...

        style="color: rgb(51, 51, 255);">jsf.ajax.request(element, event,
{execute: '@all', render: '@all'});

    ...

    };



    submitForm = function(event, form) {

    ...

        style="color: rgb(51, 51, 255);">jsf.ajax.request(form, event,
{execute: '@all', render: '@all'});

    ...

    };



ICEFaces uses submitEvent and
submitForm in their style="font-style: italic;">iceSubmitPartial and style="font-style: italic;">iceSubmit functions
respectively.  The iceSubmitPartial
and iceSubmit functions
are part of the ICEFaces Ajax Bridge that  communicate with the
server.  ICEFaces is using the keyword style="font-style: italic;">@all for both style="font-style: italic;">execute and style="font-style: italic;">render which means that all
components are processed on the server, and all components are targeted
for rendering markup back to the client.  ICEFaces sends
everything because on the server the framework determines the "dirty"
regions in a view by comparing the current rendered view with the view
that was rendered as a result of the Ajax request.



How ICEFaces Uses JSF 2.0 To Process
Ajax Requests On The Server



JSF 2.0 provides extensibility points that allow JSF Ajax
frameworks to perform customized partial processing and partial
rendering on the server.  The JSF 2.0 API provides the style="font-style: italic;">javax.faces.context.PartialViewContext.processPartial
method for this purpose.  This method performs partial
processing and partial rendering on the components identified by the
identifiers in the execute and
render lists from the
request.  ICEFaces extends javax.faces.context.PartialViewContext
with their DOMPartialViewContext
impementation:


cellpadding="2" cellspacing="2">
style="vertical-align: top; background-color: rgb(204, 255, 255);">import
javax.faces.context.PartialViewContextWrapper;

...

public class DOMPartialViewContext extends PartialViewContextWrapper {

...

    style="color: rgb(51, 51, 255);">public void processPartial(PhaseId
phaseId)
  {

    ...

        if (isRenderAll() &&
PhaseId.RENDER_RESPONSE) {

            //
Perform DOM Diffing ..

            //
Send updates as separate <update> elements using JSF 2.0
PartialResponseWriter

            ...

        } else {

           
super.processPartial(phaseId);

        }

    }

...

}



If the current processing phase is the style="font-style: italic;">Render Response Phase, ICEFaces:

  • retrieves the current DOM (for the view before rendering)
  • generates the new DOM by rendering the new view (using a special
    DOMResponseWriter)
  • determines if there are differences between the DOMs

If there are differences, then the JSF 2.0 style="font-style: italic;">javax.faces.context.PartialResponseWriter implementation
is used to write <update> elements back to the client following
the specification defined partial response format:


cellpadding="2" cellspacing="2">
style="vertical-align: top; background-color: rgb(204, 255, 255);"><partial-response>

   <changes>

      <update id="user">

         ...

      </update>

      <update id="password">

         ...

      </update>

      ...

   </changes>

</partial-response>



If there are no differences, then the JSF 2.0 style="font-style: italic;">javax.faces.context.PartialResponseWriter implementation
is used to write the single <update> element containing the
entire view markup.



Summary



ICEFaces 2.0 is still
under development, and it is one of the early component frameworks that
follow the JSF 2.0 Ajax standard.  It uses the JSF 2.0 Ajax
JavaScript API to initiate Ajax requests to the server.  It
leverages the JSF 2.0 Ajax extensibility points on the server to
process Ajax Requests and formulate the partial response to send back
to the client.  This version of ICEFaces (2.0) currently uses the href="https://javaserverfaces.dev.java.net/">mojarra  implementation
of the JSF 2.0 specification.  There will surely be more component
frameworks on board with JSF 2.0, which should go a long way towards
component interoperability.



References



href="http://www.jroller.com/tedgoddard/entry/on_the_road_to_icefaces">ICEFaces
2.0

JavaServer Faces 2.0
Specification


Project Mojarra

GlassFish





style="font-style: italic;">

Related Topics >>

Comments

This is great news, looking forward to using IceFaces 2.0 on JSF 2.0!