JSF Special Code

[b][/b]
Logging phaselistener:
public class RequestLoggingPhaseListener implements PhaseListener {

	private Log logger = LogFactory.getLog(RequestLoggingPhaseListener.class);

	public void afterPhase(PhaseEvent event) {
		// no-op
	}

	public void beforePhase(PhaseEvent event) {
		if (logger.isDebugEnabled()) {
			logger.debug("Entering JSF Phase: " + event.getPhaseId());
		}
	}

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

}

public class EventIdPhaseListener implements PhaseListener {

    /**
     * 
     */
    private static final long serialVersionUID = -3598276873000402024L;

    public void afterPhase(PhaseEvent event) {
        if (JsfUtils.isFlowRequest()) {
            FacesContext context = event.getFacesContext();
            if (context.getExternalContext().getRequestParameterMap().containsKey("_eventId")) {
                UICommand eventSource = new UICommand();
                eventSource.setTransient(true);
                eventSource.setParent(context.getViewRoot());
                eventSource.setId("_eventId");
                String eventId = (String) context.getExternalContext().getRequestParameterMap().get("_eventId");
                eventSource.setActionExpression(convertEventIdToMethodExpression(context, eventId));
                context.getViewRoot().queueEvent(new ActionEvent(eventSource));
            }
        }
    }

    public void beforePhase(PhaseEvent event) {
        // Do Nothing
    }

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

    private MethodExpression convertEventIdToMethodExpression(FacesContext facesContext, String eventId) {
        ELContext elContext = facesContext.getELContext();
        return facesContext.getApplication().getExpressionFactory().createMethodExpression(elContext, eventId,
                String.class, new Class[0]);
    }

}

    <lifecycle>
        <phase-listener>com.zenius.EventIdPhaseListener</phase-listener>
    </lifecycle> 


你可能感兴趣的:(java,xml,JSF)