dev@javaserverfaces.java.net

Re: Neil: need your portlet insight

From: Neil Griffin <neil.griffin_at_liferay.com>
Date: Wed, 20 Jan 2010 13:31:14 -0500

Hi Ed,

In a porlet environment, the portlet bridge (a subclass of javax.portlet.GenericPortlet) is responsible for doing the stuff that FacesServlet does in a servlet environment. So in other words, the FacesServlet is not used in a portlet environment.

When a postback occurs in a JSF portlet, the Portlet Lifecycle basically runs two phases that are of interest here:
        ACTION_PHASE
        RENDER_PHASE

In the ACTION_PHASE, the bridge is responsible for:
        1) Get the FC from the FCFactory
        2) Run the Faces lifecycle
        3) Save FC state in a request attribute (FacesMessages, FC.getAttributes(), etc)
        3) Call FC.release();

In the RENDER_PHASE, the bridge is responsible for:
        1) Get the FC from the FCFactory
        3) Restore FC state from request attribute
        2) Run the RenderResponse phase
        3) Call FC.release();

So I think that the text you have in the spec is fine, unless you want to include direction for portlets as well.

Best Regards,

Neil

On Jan 19, 2010, at 3:46 PM, Ed Burns wrote:

> Hello Neil, this email pertains to
> <https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1512>.
>
> Issue: 1512
>
> SECTION: SPEC Considerations
>
> First, let's assume I'll file a spec issue, targeted at 2.0 Rev a, that
> loosens the the following wording on the javadoc of
> FacesServlet.service().
>
> The very last sentance in the javadoc for FacesServlet.service() is:
>
> "In a finally block, FacesContext.release() must be called."
>
> I want to change this to:
>
> "The implementation must make it so FacesContext.release() is called
> within a finally block as late as possible in the processing for the JSF
> related portion of this request".
>
> SECTION: Impl considerations
>
> I plan to affect this change by removing the call to
> FacesContext.release() from FacesServlet.service() and moving it to a
> finally block in Mojarra's implementation of
> javax.servlet.ServletRequestListener.requestDestroyed().
>
> Ryan Lubke mentioned has reason to believe that this method is not
> called in a JSR-168 portlet environment. Rather, he asserts we can only
> rely on ServletContextListener in JSR-168.
>
> Neil, can you please share your insights about whether or not it is ok
> to make this implementation change with respect to JSR-168 portlets?
>
> Thanks,
>
> Ed
>
>
> SECTION: Modified Files
> ----------------------------
> M jsf-api/src/main/java/javax/faces/webapp/FacesServlet.java
> M jsf-ri/src/com/sun/faces/application/WebappLifecycleListener.java
>
>
> SECTION: Diffs
> ----------------------------
> Index: jsf-api/src/main/java/javax/faces/webapp/FacesServlet.java
> ===================================================================
> --- jsf-api/src/main/java/javax/faces/webapp/FacesServlet.java (revision 8290)
> +++ jsf-api/src/main/java/javax/faces/webapp/FacesServlet.java (working copy)
> @@ -322,10 +322,6 @@
> }
> }
> }
> - finally {
> - // Release the FacesContext instance for this request
> - context.release();
> - }
>
> requestEnd(); // V3 Probe hook
> }
> Index: jsf-ri/src/com/sun/faces/application/WebappLifecycleListener.java
> ===================================================================
> --- jsf-ri/src/com/sun/faces/application/WebappLifecycleListener.java (revision 8290)
> +++ jsf-ri/src/com/sun/faces/application/WebappLifecycleListener.java (working copy)
> @@ -61,6 +61,9 @@
> import com.sun.faces.util.FacesLogger;
> import java.util.Map;
> import javax.faces.component.UIViewRoot;
> +import javax.faces.context.FacesContext;
> +import javax.faces.event.ExceptionQueuedEvent;
> +import javax.faces.event.ExceptionQueuedEventContext;
> import javax.faces.event.SystemEvent;
> import javax.faces.event.PreDestroyViewMapEvent;
> import javax.faces.event.ViewMapListener;
> @@ -100,16 +103,28 @@
> *
> * @param event the notification event
> */
> - public void requestDestroyed(ServletRequestEvent event) {
> - ServletRequest request = event.getServletRequest();
> - for (Enumeration e = request.getAttributeNames(); e.hasMoreElements(); ) {
> - String beanName = (String)e.nextElement();
> - handleAttributeEvent(beanName,
> - request.getAttribute(beanName),
> - ELUtils.Scope.REQUEST);
> + public void requestDestroyed(ServletRequestEvent event) {
> + FacesContext context = FacesContext.getCurrentInstance();
> + try {
> + ServletRequest request = event.getServletRequest();
> + for (Enumeration e = request.getAttributeNames(); e.hasMoreElements();) {
> + String beanName = (String) e.nextElement();
> + handleAttributeEvent(beanName,
> + request.getAttribute(beanName),
> + ELUtils.Scope.REQUEST);
> + }
> + syncSessionScopedBeans(request);
> + } catch (Throwable t) {
> + ExceptionQueuedEventContext eventContext =
> + new ExceptionQueuedEventContext(context, t);
> + context.getApplication().publishEvent(context,
> + ExceptionQueuedEvent.class, eventContext);
> + context.getExceptionHandler().handle();
> }
> - syncSessionScopedBeans(request);
> - ApplicationAssociate.setCurrentInstance(null);
> + finally {
> + context.release();
> + ApplicationAssociate.setCurrentInstance(null);
> + }
> }
>
> /**
>
>
>
> --
> | ed.burns_at_sun.com | office: 408 884 9519 OR x31640
> | homepage: | http://ridingthecrest.com/