How to continue JSF:RENDER_RESPONSE phase after exception in END PHASE INVOKE_APPLICATION

五迷三道 提交于 2019-12-24 11:53:40

问题


I want to continue to JSF:RENDER_RESPONSE (last phase in JSF lifecylce) after getting a particular custom exception in INVOKE_APPLICATION phase.

For following action all Six JSF lifecycle phase run:

public void save(String actionID) throws Exception
{
}

What I am getting in logs is :

 START PHASE RESTORE_VIEW 1
 END PHASE RESTORE_VIEW 1
 START PHASE APPLY_REQUEST_VALUES 2
 END PHASE APPLY_REQUEST_VALUES 2
 START PHASE PROCESS_VALIDATIONS 3
 END PHASE PROCESS_VALIDATIONS 3
 START PHASE UPDATE_MODEL_VALUES 4
 END PHASE UPDATE_MODEL_VALUES 4
 START PHASE INVOKE_APPLICATION 5
 END PHASE INVOKE_APPLICATION 5
 START PHASE RENDER_RESPONSE 6
 END PHASE RENDER_RESPONSE 6

But for following action (action throwing exception):

public void save(String actionID) throws Exception
{
    throw new FieldMissingException("LLLL");
}

I am getting :

START PHASE RESTORE_VIEW 1
 END PHASE RESTORE_VIEW 1
 START PHASE APPLY_REQUEST_VALUES 2
 END PHASE APPLY_REQUEST_VALUES 2
 START PHASE PROCESS_VALIDATIONS 3
 END PHASE PROCESS_VALIDATIONS 3
 START PHASE UPDATE_MODEL_VALUES 4
 END PHASE UPDATE_MODEL_VALUES 4
 START PHASE INVOKE_APPLICATION 5
WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (http-0.0.0.0-0.0.0.0-8080-1) #{bandListController.save('Band.Create.Action.Save')}: com.alt.security.exception.FieldMissingException: LLLL: javax.faces.FacesException: #{bandListController.save('Band.Create.Action.Save')}: com.alt.security.exception.FieldMissingException: LLLL
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at javax.faces.component.UICommand.broadcast(UICommand.java:315) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
.
.
.
END PHASE INVOKE_APPLICATION 5

Render response phase is not getting executed. How to move to next phase after getting exception in APPLICATION Phase.

To handle Exception globally , I have also created ExceptionHandlerFactory and ExceptionHandler exceptionHandler-link.

@Override
public void handle()
    throws FacesException
{
    for (final Iterator<ExceptionQueuedEvent> it = getUnhandledExceptionQueuedEvents().iterator(); it.hasNext();) {
        Throwable t = it.next().getContext().getException();
        while ((t instanceof FacesException) && t.getCause() != null) {
            t = t.getCause();
        }
        if (t instanceof FieldMissingException) {
            // -->  What should I write here to stop propogation of custom exception to next phase  
            // final FacesContext facesContext = FacesContext.getCurrentInstance();
            // facesContext.responseComplete();
        }
    }
    getWrapped().handle();
}

Adding more information about project:
--> web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <display-name>AltAdminWAR</display-name>

    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

    <!-- Welcome page -->
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>

    <!-- JSF mapping -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Map these files with JSF -->

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>


    <filter>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    <error-page>
        <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/</location>
    </error-page>
    <session-config>
        <session-timeout>15</session-timeout>
    </session-config>
</web-app>

--> face-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">
    <application>
    </application>
    <lifecycle>
        <phase-listener>com.alt.security.test.LifeCycleListener</phase-listener>
    </lifecycle>
    <factory>
        <exception-handler-factory>com.alt.security.test.ExceptionHandlerFactory</exception-handler-factory>
    </factory>
</faces-config>

--> pom file entry for jsf and primeface

<dependency>
    <groupId>javax.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.0</version>
</dependency>
<dependency>
    <groupId>org.primefaces</groupId>
    <artifactId>primefaces</artifactId>
    <version>5.1</version>
</dependency>

JBoss Server : jboss-as-7.1.1.Final

来源:https://stackoverflow.com/questions/30993768/how-to-continue-jsfrender-response-phase-after-exception-in-end-phase-invoke-ap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!