4

私のコードには、単純なPhase Listener.

public class PhaseTracker implements PhaseListener {
    private static final Logger LOGGER = LoggerFactory.getLogger(PhaseTracker.class);

    @Override
    public void afterPhase(PhaseEvent pe) {
        LOGGER.debug("afterPhase " + pe.getPhaseId());
        LOGGER.debug(""+FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("haveErrors"));

    }

    @Override
    public void beforePhase(PhaseEvent pe) {
        LOGGER.debug("beforePhase " + pe.getPhaseId());
        boolean error = false;
        Iterator<FacesMessage> messageIterator = pe.getFacesContext().getMessages();
        while (messageIterator.hasNext()) {
            FacesMessage message = messageIterator.next();
            if (message.getSeverity().equals(FacesMessage.SEVERITY_ERROR)) {
                LOGGER.debug("beforePhase severity is error");
                error = true;
            }

        }

        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("haveErrors", error);
        LOGGER.debug(""+FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("haveErrors"));
    }

    @Override
    public PhaseId getPhaseId() {
        LOGGER.debug("getPhaseId");
        return PhaseId.ANY_PHASE;
    }
}

問題は、XHTMLファイル内で変数にアクセスしようとしたときに

FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("haveErrors")

nullソースがありますが、理由がわかりません。

4

1 に答える 1