struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mallya, Nithin" <Nithin.Mal...@tgslc.org>
Subject Struts-tiles-JSF integration issue + fix
Date Thu, 19 Jun 2003 19:12:57 GMT
I am working on integrating struts-tiles-JSF using the struts-faces.jar v4
I noticed the following issue

The response ends up as committed the first time you hit a page with faces
in it when you are accessing it using struts-Tiles. That is, even if you are
accessing a page with just a image on it using Faces, when it loads you get
the "Response has already been committed" error message. 

Solution:
I had to modify the ViewHandlerImpl class as follows so that if the response

was not committed then it would forward the request appropriately.
Please see the comment "Changed by Nithin" in the code where i had to make 
changes in the "renderView" method.

// Source File Name:   ViewHandlerImpl.java

package com.sun.faces.lifecycle;

import java.io.IOException;

import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import javax.faces.lifecycle.ViewHandler;
import javax.faces.tree.Tree;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.faces.util.Util;

public class ViewHandlerImpl
    implements ViewHandler
{

    public ViewHandlerImpl()
    {
    }




    public void renderView(FacesContext context)throws 
IOException,FacesException
       
    {
        if(context == null)
        {
            throw new NullPointerException(Util.getExceptionMessage
("com.sun.faces.NULL_CONTEXT_ERROR"));
        } else
        {
        	
            HttpServletRequest request = (HttpServletRequest )
context.getExternalContext().getRequest();
			HttpServletResponse response = (HttpServletResponse
)
context.getExternalContext().getResponse();

            RequestDispatcher requestDispatcher = null;
            Tree tree = context.getTree();
            String requestURI = context.getTree().getTreeId();

            requestDispatcher = request.getRequestDispatcher(requestURI);
            try{
// Changed by Nithin -- BEGIN

				if( !response.isCommitted() ) {
					requestDispatcher.forward(request, 
response);
				} else {
					requestDispatcher.include(request, 
response);
// Changed by Nithin -- END

				}
            } catch(ServletException se){
            	throw new FacesException(se);
            }
            return;
        }
    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message