Search in sources :

Example 1 with FacesMessageEntry

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));
}
Also used : FacesMessageEntry(org.apache.deltaspike.jsf.impl.message.FacesMessageEntry) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 2 with FacesMessageEntry

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
    }
}
Also used : JsfModuleConfig(org.apache.deltaspike.jsf.api.config.JsfModuleConfig) FacesMessageEntry(org.apache.deltaspike.jsf.impl.message.FacesMessageEntry) WindowMetaData(org.apache.deltaspike.jsf.impl.listener.phase.WindowMetaData) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) FacesMessage(javax.faces.application.FacesMessage)

Example 3 with FacesMessageEntry

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);
    }
}
Also used : JsfModuleConfig(org.apache.deltaspike.jsf.api.config.JsfModuleConfig) FacesMessageEntry(org.apache.deltaspike.jsf.impl.message.FacesMessageEntry) WindowMetaData(org.apache.deltaspike.jsf.impl.listener.phase.WindowMetaData) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 FacesMessageEntry (org.apache.deltaspike.jsf.impl.message.FacesMessageEntry)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ContextNotActiveException (javax.enterprise.context.ContextNotActiveException)2 JsfModuleConfig (org.apache.deltaspike.jsf.api.config.JsfModuleConfig)2 WindowMetaData (org.apache.deltaspike.jsf.impl.listener.phase.WindowMetaData)2 FacesMessage (javax.faces.application.FacesMessage)1