在我的代码中,我有一个简单的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
来源,我不明白为什么。