You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Keith Wong (Created) (JIRA)" <de...@myfaces.apache.org> on 2011/10/14 13:00:12 UTC

[jira] [Created] (MYFACES-3358) Flash created in ExceptionHandler not work

Flash created in ExceptionHandler not work
------------------------------------------

                 Key: MYFACES-3358
                 URL: https://issues.apache.org/jira/browse/MYFACES-3358
             Project: MyFaces Core
          Issue Type: Bug
          Components: JSR-314
    Affects Versions: 2.1.3
         Environment: WebSphere 8.0
            Reporter: Keith Wong


I have a custom ExceptionHandler for handling ViewExpiredException as occurred in session timeout or application restart.  I have to tell the user in the redirected page the reason for being redirected.  Here is the handler:

	public void handle() throws FacesException {
		for (Iterator<ExceptionQueuedEvent> i=getUnhandledExceptionQueuedEvents().iterator(); i.hasNext(); ) {
			ExceptionQueuedEventContext context = i.next().getContext();
			Throwable t = context.getException();
			if (t instanceof ViewExpiredException) {
				FacesContext ctx = FacesContext.getCurrentInstance();
				ViewExpiredException vee = (ViewExpiredException)t;
				try {
					ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, vee.getClass().getName(), vee.getMessage()));
					Flash flash = ctx.getExternalContext().getFlash();
					flash.put("expiredViewId", vee.getViewId());
					flash.setKeepMessages(true);

					ctx.getApplication().getNavigationHandler().handleNavigation(ctx, null, "/login?faces-redirect=true");
					ctx.renderResponse();
				}
				finally {
					i.remove();
				}
			}
		}
		super.handle();
	}

In the login.xhtml, it has #{flash.expiredViewId} and <f:messages> but both are empty when displayed.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (MYFACES-3358) Flash created in ExceptionHandler not work

Posted by "Keith Wong (Commented) (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-3358?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13146753#comment-13146753 ] 

Keith Wong commented on MYFACES-3358:
-------------------------------------

I do agree that it is not clear in the spec that how the lifecycle of a flash would be.  But I think this case should work in the mojarra implementation.  After investigation, I found that the following changes in org.apache.myfaces.lifecycle.LifecycleImpl could handle the flash in this case:

    @Override
    public void render(FacesContext facesContext) throws FacesException
    {
        //try
        //{
            // if the response is complete we should not be invoking the phase listeners
            if (isResponseComplete(facesContext, renderExecutor.getPhase(), true))
            {
                facesContext.setCurrentPhaseId(renderExecutor.getPhase());
                Flash flash = facesContext.getExternalContext().getFlash();
                flash.doPrePhaseActions(facesContext);
                flash.doPostPhaseActions(facesContext);
                return;
            }
            ...

                
> Flash created in ExceptionHandler not work
> ------------------------------------------
>
>                 Key: MYFACES-3358
>                 URL: https://issues.apache.org/jira/browse/MYFACES-3358
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: JSR-314
>    Affects Versions: 2.1.3
>         Environment: WebSphere 8.0
>            Reporter: Keith Wong
>            Assignee: Leonardo Uribe
>
> I have a custom ExceptionHandler for handling ViewExpiredException as occurred in session timeout or application restart.  I have to tell the user in the redirected page the reason for being redirected.  Here is the handler:
>         public void handle() throws FacesException {
>                 for (Iterator<ExceptionQueuedEvent> i=getUnhandledExceptionQueuedEvents().iterator(); i.hasNext(); ) {
>                         ExceptionQueuedEventContext context = i.next().getContext();
>                         Throwable t = context.getException();
>                         if (t instanceof ViewExpiredException) {
>                                 FacesContext ctx = FacesContext.getCurrentInstance();
>                                 ViewExpiredException vee = (ViewExpiredException)t;
>                                 try {
>                                         ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, vee.getClass().getName(), vee.getMessage()));
>                                         Flash flash = ctx.getExternalContext().getFlash();
>                                         flash.put("expiredViewId", vee.getViewId());
>                                         flash.setKeepMessages(true);
>                                         ctx.getApplication().getNavigationHandler().handleNavigation(ctx, null, "/login?faces-redirect=true");
>                                         ctx.renderResponse();
>                                 }
>                                 finally {
>                                         i.remove();
>                                 }
>                         }
>                 }
>                 super.handle();
>         }
> In the login.xhtml, it has #{flash.expiredViewId} and <f:messages> but both are empty when displayed.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (MYFACES-3358) Flash created in ExceptionHandler not work

Posted by "Leonardo Uribe (Commented) (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-3358?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13137429#comment-13137429 ] 

Leonardo Uribe commented on MYFACES-3358:
-----------------------------------------

Spec issue created for reference:  http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1045
                
> Flash created in ExceptionHandler not work
> ------------------------------------------
>
>                 Key: MYFACES-3358
>                 URL: https://issues.apache.org/jira/browse/MYFACES-3358
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: JSR-314
>    Affects Versions: 2.1.3
>         Environment: WebSphere 8.0
>            Reporter: Keith Wong
>            Assignee: Leonardo Uribe
>
> I have a custom ExceptionHandler for handling ViewExpiredException as occurred in session timeout or application restart.  I have to tell the user in the redirected page the reason for being redirected.  Here is the handler:
>         public void handle() throws FacesException {
>                 for (Iterator<ExceptionQueuedEvent> i=getUnhandledExceptionQueuedEvents().iterator(); i.hasNext(); ) {
>                         ExceptionQueuedEventContext context = i.next().getContext();
>                         Throwable t = context.getException();
>                         if (t instanceof ViewExpiredException) {
>                                 FacesContext ctx = FacesContext.getCurrentInstance();
>                                 ViewExpiredException vee = (ViewExpiredException)t;
>                                 try {
>                                         ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, vee.getClass().getName(), vee.getMessage()));
>                                         Flash flash = ctx.getExternalContext().getFlash();
>                                         flash.put("expiredViewId", vee.getViewId());
>                                         flash.setKeepMessages(true);
>                                         ctx.getApplication().getNavigationHandler().handleNavigation(ctx, null, "/login?faces-redirect=true");
>                                         ctx.renderResponse();
>                                 }
>                                 finally {
>                                         i.remove();
>                                 }
>                         }
>                 }
>                 super.handle();
>         }
> In the login.xhtml, it has #{flash.expiredViewId} and <f:messages> but both are empty when displayed.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira