javax.faces.event.PhaseId Java Examples

The following examples show how to use javax.faces.event.PhaseId. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CategorySelectionBean.java    From development with Apache License 2.0 6 votes vote down vote up
public PhaseListener getListener() {
    return new PhaseListener() {
        private static final long serialVersionUID = -66585096775189540L;

        public PhaseId getPhaseId() {
            return PhaseId.RENDER_RESPONSE;
        }

        public void beforePhase(PhaseEvent event) {
            unselectCategory();
        }

        public void afterPhase(PhaseEvent arg0) {
            // nothing
        }
    };
}
 
Example #2
Source File: DelegatingPhaseListenerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void beforeAndAfterPhaseWithMultipleTargets() {
	TestListener target1 = new TestListener();
	TestListener target2 = new TestListener();
	beanFactory.addBean("testListener1", target1);
	beanFactory.addBean("testListener2", target2);

	assertEquals(PhaseId.ANY_PHASE, delPhaseListener.getPhaseId());
	PhaseEvent event = new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, new MockLifecycle());

	delPhaseListener.beforePhase(event);
	assertTrue(target1.beforeCalled);
	assertTrue(target2.beforeCalled);

	delPhaseListener.afterPhase(event);
	assertTrue(target1.afterCalled);
	assertTrue(target2.afterCalled);
}
 
Example #3
Source File: EventPager.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void handleValueChange (ValueChangeEvent event)
{
    PhaseId
        phaseId = event.getPhaseId();

    String
        oldValue = (String) event.getOldValue(),
        newValue = (String) event.getNewValue();

    if (phaseId.equals(PhaseId.ANY_PHASE))
    {
        event.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
        event.queue();
    }
    else if (phaseId.equals(PhaseId.UPDATE_MODEL_VALUES))
    {
    // do you method here
    }
}
 
Example #4
Source File: DeltaSpikePhaseListener.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
private void processInitView(PhaseEvent event)
{
    if (event.getPhaseId().equals(PhaseId.RESTORE_VIEW) && !isRedirectRequest(event.getFacesContext()))
    {
        return;
    }

    //TODO check if we have to restrict the other callbacks as well
    //leads to a call of @BeforePhase but not the corresponding @AfterPhase call of the corresponding callbacks

    //TODO don't call the callbacks in case of an initial redirct
    //was:
    /*
    if(Boolean.TRUE.equals(event.getFacesContext().getExternalContext().getRequestMap()
            .get(WindowContextManagerObserver.INITIAL_REDIRECT_PERFORMED_KEY)))
    {
        return;
    }
    */

    FacesContext facesContext = event.getFacesContext();
    if (facesContext.getViewRoot() != null && facesContext.getViewRoot().getViewId() != null)
    {
        processInitView(event.getFacesContext().getViewRoot().getViewId());
    }
}
 
Example #5
Source File: UndefinedExceptionHandler.java    From web-budget with GNU General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @param context
 * @param exception
 */
@Override
public void handle(FacesContext context, Throwable exception) {

    final HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

    request.setAttribute(ERROR_EXCEPTION + "_stacktrace", exception);

    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
        throw new FacesException(exception);
    }

    request.setAttribute(ERROR_EXCEPTION_TYPE, exception.getClass().getName());
    request.setAttribute(ERROR_MESSAGE, exception.getMessage());
    request.setAttribute(ERROR_REQUEST_URI, request.getHeader("Referer"));
    request.setAttribute(ERROR_STATUS_CODE, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

    final String errorPage = this.getErrorPage(exception);

    context.getApplication().getNavigationHandler().handleNavigation(context, null, errorPage);

    context.renderResponse();
}
 
Example #6
Source File: DeltaSpikePhaseListener.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
@Override
public void beforePhase(PhaseEvent phaseEvent)
{
    if (!this.activated)
    {
        return;
    }

    if (this.viewConfigResolver == null)
    {
        lazyInit();
    }

    processInitView(phaseEvent);

    //delegate to JsfRequestLifecyclePhaseListener as a last step
    this.jsfRequestLifecyclePhaseListener.beforePhase(phaseEvent);

    if (PhaseId.RENDER_RESPONSE.equals(phaseEvent.getPhaseId()))
    {
        onBeforeRenderResponse(phaseEvent.getFacesContext());
    }
}
 
Example #7
Source File: UndefinedExceptionHandler.java    From library with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @param context
 * @param exception
 */
@Override
public void handle(FacesContext context, Throwable exception) {

    final HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

    request.setAttribute(ERROR_EXCEPTION + "_stacktrace", exception);

    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
        throw new FacesException(exception);
    }

    request.setAttribute(ERROR_EXCEPTION_TYPE, exception.getClass().getName());
    request.setAttribute(ERROR_MESSAGE, exception.getMessage());
    request.setAttribute(ERROR_REQUEST_URI, request.getHeader("Referer"));
    request.setAttribute(ERROR_STATUS_CODE, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

    final String errorPage = this.getErrorPage(exception);

    context.getApplication().getNavigationHandler().handleNavigation(context, null, errorPage);

    context.renderResponse();
}
 
Example #8
Source File: DelegatingPhaseListenerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void beforeAndAfterPhaseWithMultipleTargets() {
	TestListener target1 = new TestListener();
	TestListener target2 = new TestListener();
	beanFactory.addBean("testListener1", target1);
	beanFactory.addBean("testListener2", target2);

	assertEquals(delPhaseListener.getPhaseId(), PhaseId.ANY_PHASE);
	PhaseEvent event = new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, new MockLifecycle());

	delPhaseListener.beforePhase(event);
	assertTrue(target1.beforeCalled);
	assertTrue(target2.beforeCalled);

	delPhaseListener.afterPhase(event);
	assertTrue(target1.afterCalled);
	assertTrue(target2.afterCalled);
}
 
Example #9
Source File: DeltaSpikePhaseListener.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Override
public void afterPhase(PhaseEvent phaseEvent)
{
    if (!this.activated)
    {
        return;
    }

    if (this.viewConfigResolver == null)
    {
        lazyInit();
    }

    processInitView(phaseEvent);

    if (PhaseId.RESTORE_VIEW.equals(phaseEvent.getPhaseId()))
    {
        onAfterRestoreView(phaseEvent.getFacesContext());

    }
    else if (PhaseId.RENDER_RESPONSE.equals(phaseEvent.getPhaseId()))
    {
        onAfterRenderResponse(phaseEvent.getFacesContext());
    }

    //delegate to JsfRequestLifecyclePhaseListener as a last step
    this.jsfRequestLifecyclePhaseListener.afterPhase(phaseEvent);
}
 
Example #10
Source File: UIDataSourceIterator.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
@Override
    public void queueEvent(FacesEvent event) {
        if ((event instanceof ToggleRowEvent) || (event instanceof ToggleDetailEvent)) {
            if (isPartialExecute()) {
                event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
            } else {
                event.setPhaseId(PhaseId.INVOKE_APPLICATION);
            }
            // We don't need to wrap it as this is just a command action to the table
            super.queueEvent(event);
        } else {
//            event = new FacesEventWrapper(this, event);
            super.queueEvent(event);
        }
    }
 
Example #11
Source File: PhaseListenerBean.java    From tutorials with MIT License 5 votes vote down vote up
public void beforeListener(PhaseEvent event) {
    if (!event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
        return;
    }
    UIViewRoot root = event.getFacesContext().getViewRoot();

    boolean showNewFeature = showNewFeatureForIp(event);

    processComponentTree(root, event, showNewFeature);
}
 
Example #12
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example #13
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase of the
 * request processing lifecycle is about to begin.
 */
public void beforePhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
		FacesContext facesContext = event.getFacesContext();
		restoreMessages(facesContext);
	}
}
 
Example #14
Source File: MessageHandler.java    From javaee8-jsf-sample with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example #15
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example #16
Source File: AbstractDataView.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
@Override
public void processUpdates(FacesContext context) {
    if (ExtLibUtil.isXPages852()) {
        processFacetsForPhase = PhaseId.UPDATE_MODEL_VALUES;
    }
    try {
        super.processUpdates(context);
    }
    finally {
        processFacetsForPhase = null;
    }
}
 
Example #17
Source File: AbstractPager.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
@Override
public void queueEvent(FacesEvent e) {
       if (e instanceof PagerEvent) {
           if (isPartialExecute()) {
               e.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
           } else {
               e.setPhaseId(PhaseId.INVOKE_APPLICATION);
           }
       }
       super.queueEvent(e);
   }
 
Example #18
Source File: AbstractDataView.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
@Override
public void processValidators(FacesContext context) {
    if (ExtLibUtil.isXPages852()) {
        processFacetsForPhase = PhaseId.PROCESS_VALIDATIONS;
    }
    try {
        super.processValidators(context);
    }
    finally {
        processFacetsForPhase = null;
    }
}
 
Example #19
Source File: DelegatingPhaseListenerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void beforeAndAfterPhaseWithSingleTarget() {
	TestListener target = new TestListener();
	beanFactory.addBean("testListener", target);

	assertEquals(PhaseId.ANY_PHASE, delPhaseListener.getPhaseId());
	PhaseEvent event = new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, new MockLifecycle());

	delPhaseListener.beforePhase(event);
	assertTrue(target.beforeCalled);

	delPhaseListener.afterPhase(event);
	assertTrue(target.afterCalled);
}
 
Example #20
Source File: MessageHandler.java    From spring4-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase of the
 * request processing lifecycle is about to begin.
 */
public void beforePhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
		FacesContext facesContext = event.getFacesContext();
		restoreMessages(facesContext);
	}
}
 
Example #21
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase of the
 * request processing lifecycle is about to begin.
 */
public void beforePhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
		FacesContext facesContext = event.getFacesContext();
		restoreMessages(facesContext);
	}
}
 
Example #22
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example #23
Source File: ConstraintViolationExceptionHandler.java    From web-budget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @param context
 * @param exception
 */
@Override
public void handle(FacesContext context, Throwable exception) {

    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
        throw new FacesException(exception);
    }

    FacesUtils.clearMessages(context);
    Messages.add(FacesMessage.SEVERITY_ERROR, null, MessageSource.get("error.core.constraint-violation"));

    context.renderResponse();
}
 
Example #24
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example #25
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example #26
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase of the
 * request processing lifecycle is about to begin.
 */
public void beforePhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
		FacesContext facesContext = event.getFacesContext();
		restoreMessages(facesContext);
	}
}
 
Example #27
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase of the
 * request processing lifecycle is about to begin.
 */
public void beforePhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
		FacesContext facesContext = event.getFacesContext();
		restoreMessages(facesContext);
	}
}
 
Example #28
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example #29
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase has just
 * been completed.
 */
public void afterPhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES ||
			event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS ||
			event.getPhaseId() == PhaseId.UPDATE_MODEL_VALUES || 
			event.getPhaseId() == PhaseId.INVOKE_APPLICATION) {

		FacesContext facesContext = event.getFacesContext();
		saveMessages(facesContext);
	}

}
 
Example #30
Source File: MessageHandler.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a notification that the processing for a particular phase of the
 * request processing lifecycle is about to begin.
 */
public void beforePhase(PhaseEvent event) {

	if(event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
		FacesContext facesContext = event.getFacesContext();
		restoreMessages(facesContext);
	}
}