Java Code Examples for javax.faces.application.FacesMessage#SEVERITY_WARN

The following examples show how to use javax.faces.application.FacesMessage#SEVERITY_WARN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeneralBean.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
public void showGrowlMessage() {
	String severityRaw = BeanUtil.getRequestParam("Severity");
	String summary = BeanUtil.getRequestParam("Summary");
	String detail = BeanUtil.getRequestParam("Detail");

       Severity severity;

       if("WARN".equals(severityRaw)) {
		severity = FacesMessage.SEVERITY_WARN;
       } else if("ERROR".equals(severityRaw)) {
		severity = FacesMessage.SEVERITY_ERROR;
	} else {
		severity = FacesMessage.SEVERITY_INFO;
	}

	BeanUtil.showMessage(severity, summary, detail);
}
 
Example 2
Source File: FormLayoutRenderer.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
private void startErrorSummaryContainer(FacesContext context, ResponseWriter w, FormLayout c, FacesMessage.Severity sev) throws IOException {
    w.startElement("div", c); // $NON-NLS-1$
    String style = (String)getProperty(PROP_ERRORSUMMARYSTYLE);
    if(sev==FacesMessage.SEVERITY_WARN) {
        style = (String)getProperty(PROP_WARNSUMMARYSTYLE);
    } else if(sev==FacesMessage.SEVERITY_INFO) {
        style = (String)getProperty(PROP_INFOSUMMARYSTYLE);
    }
    if(StringUtil.isNotEmpty(style)) {
        w.writeAttribute("style", style, null); // $NON-NLS-1$
    }
    String cls = (String)getProperty(PROP_ERRORSUMMARYCLASS);
    if(sev==FacesMessage.SEVERITY_WARN) {
        cls = (String)getProperty(PROP_WARNSUMMARYCLASS);
    } else if(sev==FacesMessage.SEVERITY_INFO) {
        cls = (String)getProperty(PROP_INFOSUMMARYCLASS);
    }
    if(StringUtil.isNotEmpty(cls)) {
        w.writeAttribute("class", cls, null); // $NON-NLS-1$
    }
    w.writeAttribute("role", "alert", null); // $NON-NLS-1$ $NON-NLS-2$
}
 
Example 3
Source File: JSFUtils.java    From development with Apache License 2.0 5 votes vote down vote up
public static boolean hasWarnings(FacesContext fc) {
    for (Iterator<FacesMessage> i = fc.getMessages(); i.hasNext();) {
        FacesMessage m = i.next();
        if (FacesMessage.SEVERITY_WARN == m.getSeverity()) {
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: ManageLanguageCtrlTest.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * @param contextStub
 */
@SuppressWarnings("unused")
private void givenJSFUtilsMessage(FacesContextStub contextStub, String key,
        String value, Object[] params) {
    setResourceBundle(contextStub, key, value);

    FacesMessage firstFM = new FacesMessage(FacesMessage.SEVERITY_WARN,
            value, null);
    firstFM.setDetail(value);
    firstFM.setSummary(value);
    contextStub.addMessage(null, firstFM);
}
 
Example 5
Source File: DivMessagesRenderer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
    * Combine the messages from the redirect-safe messages bean and those
    * stored in the faces context.  If there are messages associated with
    * individual components, but no global messages, then add a global message
    * pointing the user to check for component messages ('See messages below'
    * for instance).
 *
    * @param context
 * @param component
 * @return
 */
   private List combineMessages(FacesContext context, UIComponent component) {
       List redirectSafeMessages = ((MessagingBean)JsfUtil.resolveVariable("messagingBean")).getMessagesAndClear();
       List allMessages = new ArrayList(redirectSafeMessages);
       boolean globalOnly = ((UIMessages)component).isGlobalOnly();

       Iterator allFacesMessages = context.getMessages();
       Iterator globalFacesMessages = context.getMessages(null);

       Collection componentBoundMessages = getComponentBoundMessages(allFacesMessages, globalFacesMessages);
       Iterator facesMessages;
       if(globalOnly) {
           facesMessages = globalFacesMessages;
       } else {
           facesMessages = allFacesMessages;
       }

       // If this is a global only component, and there are no global messages,
       // and there are no redirect-safe messages (which are always global), and
       // there are component-bound messages, then add a global message telling
       // the user to look for the component-bound messages.
       if(globalOnly && redirectSafeMessages.size() == 0 && !globalFacesMessages.hasNext() && componentBoundMessages.size() != 0) {
           FacesMessage seeBelowMessage = new FacesMessage(FacesMessage.SEVERITY_WARN, JsfUtil.getLocalizedMessage("validation_messages_present"), null);
           allMessages.add(seeBelowMessage);
       }

       // We've already iterated over the facesMessage iterator, so we need to get them again so we can iterate again.
       // This is ugly... is there a better way to do this?
       if(globalOnly) {
           facesMessages = context.getMessages(null);
       } else {
           facesMessages = context.getMessages();
       }

       for(Iterator msgs = facesMessages; facesMessages.hasNext();) {
           allMessages.add(facesMessages.next());
       }
	return allMessages;
}
 
Example 6
Source File: FormLayoutRenderer.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
protected void writeErrorSummaryContent(FacesContext context, ResponseWriter w, FormLayout c, Iterator<FacesMessage> msg) throws IOException {
    boolean fatal = false;
    boolean err = false;
    boolean warn = false;
    boolean info = false;
    List<FacesMessage> l = new ArrayList<FacesMessage>();
    while(msg.hasNext()) {
        FacesMessage m = msg.next();
        l.add(m);
        if(m.getSeverity()==FacesMessage.SEVERITY_ERROR) {
            err = true;
        } else if(m.getSeverity()==FacesMessage.SEVERITY_WARN) {
            warn = true;
        } else if(m.getSeverity()==FacesMessage.SEVERITY_INFO) {
            info = true;
        } else if(m.getSeverity()==FacesMessage.SEVERITY_FATAL) {
            fatal = true;
        }
    }
    if( fatal ){
        writeErrorSummaryMainText(context, w, c, FacesMessage.SEVERITY_FATAL);
        writeErrorSummaryRows(context, w, c, new MsgIterator(l, FacesMessage.SEVERITY_FATAL));
    }
    if(err) {
        writeErrorSummaryMainText(context, w, c, FacesMessage.SEVERITY_ERROR);
        writeErrorSummaryRows(context, w, c, new MsgIterator(l, FacesMessage.SEVERITY_ERROR));
    }
    if(warn) {
        writeErrorSummaryMainText(context, w, c, FacesMessage.SEVERITY_WARN);
        writeErrorSummaryRows(context, w, c, new MsgIterator(l, FacesMessage.SEVERITY_WARN));
    }
    if(info) {
        writeErrorSummaryMainText(context, w, c, FacesMessage.SEVERITY_INFO);
        writeErrorSummaryRows(context, w, c, new MsgIterator(l, FacesMessage.SEVERITY_INFO));
    }
}
 
Example 7
Source File: FormLayoutRenderer.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
private void writeErrorSummaryMessage(FacesContext context, ResponseWriter w, FormLayout c, FacesMessage.Severity sev) throws IOException {
    String mainText = c.getErrorSummaryText();
    if(StringUtil.isEmpty(mainText)) {
        if(sev==FacesMessage.SEVERITY_WARN) {
            mainText = (String)getProperty(PROP_WARNSUMMARYMAINTEXT);
        } else if(sev==FacesMessage.SEVERITY_INFO) {
            mainText = (String)getProperty(PROP_INFOSUMMARYMAINTEXT);
        }else {
            mainText = (String)getProperty(PROP_ERRORSUMMARYMAINTEXT);
        }
    }
    writeErrorMessage(context, w, c, sev, mainText);
}
 
Example 8
Source File: FormLayoutRenderer.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
protected void writeErrorMessage(FacesContext context, ResponseWriter w, FormLayout c, FacesMessage.Severity sev, String text) throws IOException {
    if(sev==FacesMessage.SEVERITY_ERROR) {
        writeErrorMessage(context, w, c, text);
    } else if(sev==FacesMessage.SEVERITY_WARN) {
        writeWarnMessage(context, w, c, text);
    } else if(sev==FacesMessage.SEVERITY_INFO) {
        writeInfoMessage(context, w, c, text);
    } else if(sev == FacesMessage.SEVERITY_FATAL){
        writeFatalMessage(context, w, c, text);
    }
}
 
Example 9
Source File: DivMessagesRenderer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
    * Combine the messages from the redirect-safe messages bean and those
    * stored in the faces context.  If there are messages associated with
    * individual components, but no global messages, then add a global message
    * pointing the user to check for component messages ('See messages below'
    * for instance).
 *
    * @param context
 * @param component
 * @return
 */
   private List combineMessages(FacesContext context, UIComponent component) {
       List redirectSafeMessages = ((MessagingBean)JsfUtil.resolveVariable("messagingBean")).getMessagesAndClear();
       List allMessages = new ArrayList(redirectSafeMessages);
       boolean globalOnly = ((UIMessages)component).isGlobalOnly();

       Iterator allFacesMessages = context.getMessages();
       Iterator globalFacesMessages = context.getMessages(null);

       Collection componentBoundMessages = getComponentBoundMessages(allFacesMessages, globalFacesMessages);
       Iterator facesMessages;
       if(globalOnly) {
           facesMessages = globalFacesMessages;
       } else {
           facesMessages = allFacesMessages;
       }

       // If this is a global only component, and there are no global messages,
       // and there are no redirect-safe messages (which are always global), and
       // there are component-bound messages, then add a global message telling
       // the user to look for the component-bound messages.
       if(globalOnly && redirectSafeMessages.size() == 0 && !globalFacesMessages.hasNext() && componentBoundMessages.size() != 0) {
           FacesMessage seeBelowMessage = new FacesMessage(FacesMessage.SEVERITY_WARN, JsfUtil.getLocalizedMessage("validation_messages_present"), null);
           allMessages.add(seeBelowMessage);
       }

       // We've already iterated over the facesMessage iterator, so we need to get them again so we can iterate again.
       // This is ugly... is there a better way to do this?
       if(globalOnly) {
           facesMessages = context.getMessages(null);
       } else {
           facesMessages = context.getMessages();
       }

       for(Iterator msgs = facesMessages; facesMessages.hasNext();) {
           allMessages.add(facesMessages.next());
       }
	return allMessages;
}
 
Example 10
Source File: SsnConverter.java    From ddd-javaee7 with Apache License 2.0 5 votes vote down vote up
@Override
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) {
	if (s != null) {
		try {
			return Ssn.of(s);
		}
		catch (Exception e) {
			throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_WARN, "Invalid SSN", null));
		}
	}
	return null;
}
 
Example 11
Source File: ResponseHandler.java    From development with Apache License 2.0 4 votes vote down vote up
static FacesMessage.Severity mapToFaces(ReturnType type) {
    if (type == ReturnType.WARNING) {
        return FacesMessage.SEVERITY_WARN;
    }
    return FacesMessage.SEVERITY_INFO;
}
 
Example 12
Source File: FacesMessages.java    From BootsFaces-OSP with Apache License 2.0 4 votes vote down vote up
public static void warning(String refItem, String summary, String detail) {
	FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_WARN, summary, detail);
	reportMessage(refItem, facesMsg);
}
 
Example 13
Source File: TaskHome.java    From ee7-sandbox with Apache License 2.0 4 votes vote down vote up
public void deleteTask(Long id) {

        log.log(Level.INFO, "delete task of id@{0}", id);

        Task task = taskRepository.findById(id);

        if (task == null) {
            throw new TaskNotFoundException(id);
        }

        taskRepository.deleteById(id);

        // retrieve all tasks
        retrieveAllTasks();

        FacesMessage deleteInfo = new FacesMessage(FacesMessage.SEVERITY_WARN, "Task is deleted!", "Task is deleted!");
        FacesContext.getCurrentInstance().addMessage(null, deleteInfo);
    }
 
Example 14
Source File: TaskHome.java    From spring4-sandbox with Apache License 2.0 4 votes vote down vote up
public void deleteTask(Long id) {

		log.debug("delete task of id@" + id);

		Task task = taskRepository.findOne(id);

		if (task == null) {
			throw new TaskNotFoundException(id);
		}

		taskRepository.delete(id);

		// retrieve all tasks
		retrieveAllTasks();
		
		FacesMessage deleteInfo= new FacesMessage(FacesMessage.SEVERITY_WARN, "Task is deleted!",  "Task is deleted!");
		FacesContext.getCurrentInstance().addMessage(null, deleteInfo);
	}
 
Example 15
Source File: TaskHome.java    From javaee8-jsf-sample with GNU General Public License v3.0 3 votes vote down vote up
public void deleteTask(Long id) {

        log.log(Level.INFO, "delete task of id@{0}", id);

        Task task = taskService.findById(id);
        taskService.deleteById(id);

        // retrieve all tasks
        retrieveAllTasks();

        FacesMessage deleteInfo = new FacesMessage(FacesMessage.SEVERITY_WARN, "Task is deleted!", "Task is deleted!");
        FacesContext.getCurrentInstance().addMessage(null, deleteInfo);
    }