Search in sources :

Example 1 with WindowMetaData

use of org.apache.deltaspike.jsf.impl.listener.phase.WindowMetaData 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 2 with WindowMetaData

use of org.apache.deltaspike.jsf.impl.listener.phase.WindowMetaData 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

ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)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 FacesMessageEntry (org.apache.deltaspike.jsf.impl.message.FacesMessageEntry)2 List (java.util.List)1 FacesMessage (javax.faces.application.FacesMessage)1