use of org.apache.deltaspike.jsf.impl.message.FacesMessageEntry in project deltaspike by apache.
the class DeltaSpikeFacesContextWrapper method addMessage.
/**
* Adds the {@link FacesMessage} also to a request scoped list to allow to preserve them later on
* (in case of redirects)
*
* {@inheritDoc}
*/
@Override
public void addMessage(String componentId, FacesMessage facesMessage) {
this.wrappedFacesContext.addMessage(componentId, facesMessage);
//don't store it directly in the window context - it would trigger a too early restore (in some cases)
Map<String, Object> requestMap = getExternalContext().getRequestMap();
@SuppressWarnings({ "unchecked" }) List<FacesMessageEntry> facesMessageEntryList = (List<FacesMessageEntry>) requestMap.get(FacesMessageEntry.class.getName());
if (facesMessageEntryList == null) {
facesMessageEntryList = new CopyOnWriteArrayList<FacesMessageEntry>();
requestMap.put(FacesMessageEntry.class.getName(), facesMessageEntryList);
}
facesMessageEntryList.add(new FacesMessageEntry(componentId, facesMessage));
}
use of org.apache.deltaspike.jsf.impl.message.FacesMessageEntry 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
}
}
use of org.apache.deltaspike.jsf.impl.message.FacesMessageEntry 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);
}
}
Aggregations