javax.faces.event.PhaseEvent Java Examples

The following examples show how to use javax.faces.event.PhaseEvent. 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: 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 #2
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 #3
Source File: DelegatingPhaseListenerTests.java    From java-technology-stack 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 #4
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 #5
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 #6
Source File: LocaleListener.java    From development with Apache License 2.0 5 votes vote down vote up
public void beforePhase(PhaseEvent event) {
    PhaseId phaseId = event.getPhaseId();
    if (PhaseId.PROCESS_VALIDATIONS.equals(phaseId)
            || PhaseId.RENDER_RESPONSE.equals(phaseId)) {
        JSFUtils.verifyViewLocale();
    }
}
 
Example #7
Source File: NoCachePhaseListenerTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
    response = new HttpServletResponseStub() {
        private HashMap<String, String> map = new HashMap<String, String>();

        @Override
        public String getHeader(String arg0) {
            return map.get(arg0);
        }

        @Override
        public void addHeader(String key, String value) {
            map.put(key, value);
        }
    };
    event = mock(PhaseEvent.class);
    facesContext = mock(FacesContextStub.class);
    externalContext = mock(ExternalContextStub.class);

    noCachePhaseListener = new NoCachePhaseListener() {
        private static final long serialVersionUID = 4585977494122628808L;
    };

    doReturn(facesContext).when(event).getFacesContext();
    doReturn(externalContext).when(facesContext).getExternalContext();
    doReturn(response).when(externalContext).getResponse();

}
 
Example #8
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 #9
Source File: CachePhaseListener.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void beforePhase(PhaseEvent phaseEvent) {
    FacesContext facesContext = phaseEvent.getFacesContext();
    HttpServletResponse response =
            (HttpServletResponse) facesContext.getExternalContext().getResponse();

    response.addHeader("Pragma", "no-cache");
    response.addHeader("Cache-Control", "no-cache");
    response.addHeader("Cache-Control", "no-store");
    response.addHeader("Cache-Control", "must-revalidate");
    response.addHeader("Expires", "Wed, 1 Jan 2008 05:00:00 GMT");     //in the past
    response.setContentType("text/html; charset=UTF-8");
}
 
Example #10
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 #11
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 #12
Source File: MessageHandler.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * save messages after APPLY_REQUEST_VALUES, PROCESS_VALIDATIONS,
 * INVOKE_APPLICATION
 */
public void afterPhase(PhaseEvent event) {
    if (event.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES
            || event.getPhaseId() == PhaseId.PROCESS_VALIDATIONS
            || 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 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 #15
Source File: PhaseLoggerListener.java    From development with Apache License 2.0 5 votes vote down vote up
public void afterPhase(PhaseEvent event) {
    if (logger.isDebugLoggingEnabled()) {
        UIViewRoot viewRoot = event.getFacesContext().getViewRoot();
        if (viewRoot != null) {
            logger.logDebug("END PHASE " + event.getPhaseId() + " for view " + viewRoot.getViewId() + "\n------------------");
        }
    }
}
 
Example #16
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 #17
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 #18
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 #19
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 #20
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 #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 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 #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 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 #23
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 #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 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 #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 development with Apache License 2.0 5 votes vote down vote up
/**
 * in RENDER_RESPONSE restore facesMessages
 */
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: NoCachePhaseListener.java    From development with Apache License 2.0 5 votes vote down vote up
@Override
public void beforePhase(PhaseEvent phaseEvent) {
    FacesContext facesContext = phaseEvent.getFacesContext();
    HttpServletResponse response = (HttpServletResponse) facesContext
            .getExternalContext().getResponse();
    response.addHeader("Pragma", "no-cache");
    response.addHeader("Cache-Control", "no-cache,no-store,must-revalidate");
    response.addHeader("Expires", "0");

}
 
Example #30
Source File: PhaseLoggerListener.java    From development with Apache License 2.0 5 votes vote down vote up
public void beforePhase(PhaseEvent event) {
    if (logger.isDebugLoggingEnabled()) {
        List<FacesMessage> msgs = event.getFacesContext().getMessageList();
        UIViewRoot viewRoot = event.getFacesContext().getViewRoot();
        if (viewRoot != null) {
            logger.logDebug("------------------\nSTART PHASE: " + viewRoot.getViewId());
            for (FacesMessage msg : msgs) {
                logger.logDebug("Message " + msg.getSummary() + " :: " + msg.getDetail());
            }
        }
    }
}