use of org.apache.deltaspike.jsf.api.config.JsfModuleConfig in project deltaspike by apache.
the class JsfUtils method saveFacesMessages.
public static void saveFacesMessages(ExternalContext externalContext) {
JsfModuleConfig jsfModuleConfig = BeanProvider.getContextualReference(JsfModuleConfig.class);
if (!jsfModuleConfig.isAlwaysKeepMessages()) {
return;
}
try {
WindowMetaData windowMetaData = BeanProvider.getContextualReference(WindowMetaData.class);
Map<String, Object> requestMap = externalContext.getRequestMap();
@SuppressWarnings({ "unchecked" }) List<FacesMessageEntry> facesMessageEntryList = (List<FacesMessageEntry>) requestMap.get(FacesMessageEntry.class.getName());
if (facesMessageEntryList == null) {
facesMessageEntryList = new CopyOnWriteArrayList<FacesMessageEntry>();
}
windowMetaData.setFacesMessageEntryList(facesMessageEntryList);
} catch (ContextNotActiveException e) {
// TODO log it in case of project-stage development
// we can't handle it correctly -> delegate to the jsf-api (which has some restrictions esp. before v2.2)
FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
}
}
use of org.apache.deltaspike.jsf.api.config.JsfModuleConfig in project deltaspike by apache.
the class JsfUtils method tryToRestoreMessages.
public static void tryToRestoreMessages(FacesContext facesContext) {
JsfModuleConfig jsfModuleConfig = BeanProvider.getContextualReference(JsfModuleConfig.class);
if (!jsfModuleConfig.isAlwaysKeepMessages()) {
return;
}
try {
WindowMetaData windowMetaData = BeanProvider.getContextualReference(WindowMetaData.class);
@SuppressWarnings({ "unchecked" }) List<FacesMessageEntry> facesMessageEntryList = windowMetaData.getFacesMessageEntryList();
List<FacesMessage> originalMessageList = new ArrayList<FacesMessage>(facesContext.getMessageList());
if (facesMessageEntryList != null) {
for (FacesMessageEntry messageEntry : facesMessageEntryList) {
if (isNewMessage(originalMessageList, messageEntry.getFacesMessage())) {
facesContext.addMessage(messageEntry.getComponentId(), messageEntry.getFacesMessage());
}
}
facesMessageEntryList.clear();
}
} catch (ContextNotActiveException e) {
// TODO discuss how we handle it
}
}
Aggregations