You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shale.apache.org by Adrian Gonzalez <ad...@yahoo.fr> on 2006/10/11 17:35:46 UTC

ViewPhaseListener infinite loop with exception handler

Hello, 

I'm having a hard time figuring out the best way to
manage unchecked exceptions with JSF and Shale (i'm a
newbie with those technologies).

I think I've found a bug with Shale 1.0.3.

The view controller on my JSF page throws a runtime
exception if a text box has a value of A.

The test case is :
1. I ask the rendering of the page.
2. I submit the page with text box value = A.
3. Shale Exception handler calls my exception page.
4. I use the back button on my IE browser.
5. I submit once more the original page with jtext box
value=A.
Shale ViewPhaseListener executes an infinite loop
(since FacesConstants.EXCEPTIONS_LIST attribute of the
request is never removed). I've modified the shale
code and it works better, but perhaps 
the origin of the problem is my misunderstanding.

Thank you very much for your help.


Here's an extract of my configuration :
In web.xml :
	<context-param>
		<description>
		</description>
	
<param-name>org.apache.shale.view.EXCEPTION_DISPATCH_PATH</param-name>
	
<param-value>/faces/exception/exception.jsp</param-value>
	</context-param>
In faces-config.xml :
	<managed-bean>
	
<managed-bean-name>org$apache$shale$view$EXCEPTION_HANDLER</managed-bean-name>
	
<managed-bean-class>org.apache.shale.view.impl.DefaultExceptionHandler</managed-bean-class>
		<managed-bean-scope>application</managed-bean-scope>
	</managed-bean>
	<managed-bean>
	
<managed-bean-name>org$apache$shale$view$VIEW_CALLBACKS</managed-bean-name>
	
<managed-bean-class>org.apache.shale.view.faces.ViewControllerCallbacks</managed-bean-class>
		<managed-bean-scope>application</managed-bean-scope>
	</managed-bean>

	<lifecycle>
	 
<phase-listener>org.apache.shale.view.faces.ViewPhaseListener</phase-listener>
	</lifecycle>
	
	<application>
	
<variable-resolver>com.ibm.faces.databind.SelectItemsVarResolver</variable-resolver>
	
<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
	
<property-resolver>com.ibm.faces.databind.SelectItemsPropResolver</property-resolver>
	    <action-listener>
	      org.apache.shale.view.faces.ViewActionListener
	    </action-listener>
	    <view-handler>
	      org.apache.shale.view.faces.ViewViewHandler
	    </view-handler>
	</application>	


So, I just modified the
ViewPhaseListener.afterInvokeApplication in order to
remove this attribute just before forwardnig to the
error page :
Here's the extract of the new code :
        List list = (List)
         
econtext.getRequestMap().get(FacesConstants.EXCEPTIONS_LIST);
        if (list == null) {
            return;
        }

        // Has the user specified a forwarding URL for
handling exceptions?
        String path =
         
econtext.getInitParameter(Constants.EXCEPTION_DISPATCH_PATH);
        if (path == null) {
            return;
        }

        // Forward control to the specified path
instead of allowing
        // rendering to complete, while simulating
container error handling
        try {
            // Set up request attributes reflecting
the error conditions,
            // similar to what is passed to an error
handler by the servlet
            // container (see Section 9.9.1 of the
Servlet Specification)
            ApplicationException exception = new
ApplicationException(list);
            Map map = econtext.getRequestMap();
            map.put("javax.servlet.error.status_code",
new Integer(200)); // Not an HTTP error
           
map.put("javax.servlet.error.exception_type",
ApplicationException.class);
            map.put("javax.servlet.error.message",
exception.getMessage());
            map.put("javax.servlet.error.exception",
exception);
            StringBuffer sb = new StringBuffer("");
            if (econtext.getRequestServletPath() !=
null) {
               
sb.append(econtext.getRequestServletPath());
            }
            if (econtext.getRequestPathInfo() != null)
{
               
sb.append(econtext.getRequestPathInfo());
            }
            map.put("javax.servlet.error.request_uri",
sb.toString());
           
map.put("javax.servlet.error.servlet_name",
"javax.faces.webapp.FacesServlet"); // Best we can do
...

            //CHANGE in order to avoid infinite loop
           
econtext.getRequestMap().remove(FacesConstants.EXCEPTIONS_LIST);
            //END CHANGE




	
	
		
___________________________________________________________________________ 
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
Demandez à ceux qui savent sur Yahoo! Questions/Réponses
http://fr.answers.yahoo.com