Java Code Examples for javax.faces.context.FacesContext#getMessages()
The following examples show how to use
javax.faces.context.FacesContext#getMessages() .
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: MessageHandler.java From ee8-sandbox with Apache License 2.0 | 6 votes |
/** * Remove the messages that are not associated with any particular component * from the faces context and store them to the user's session. * * @return the number of removed messages. */ private int saveMessages(FacesContext facesContext) { // remove messages from the context List<FacesMessage> messages = new ArrayList<FacesMessage>(); for(Iterator<FacesMessage> i = facesContext.getMessages(null); i.hasNext(); ) { messages.add(i.next()); i.remove(); } // store them in the session if(messages.size() == 0) { return 0; } Map<String, Object> sessionMap = facesContext.getExternalContext().getSessionMap(); // if there already are messages @SuppressWarnings("unchecked") List<FacesMessage> existingMessages = (List<FacesMessage>) sessionMap.get(sessionToken); if(existingMessages != null) { existingMessages.addAll(messages); } else { sessionMap.put(sessionToken, messages); // if these are the first messages } return messages.size(); }
Example 2
Source File: MessageHandler.java From ee8-sandbox with Apache License 2.0 | 6 votes |
/** * Remove the messages that are not associated with any particular component * from the faces context and store them to the user's session. * * @return the number of removed messages. */ private int saveMessages(FacesContext facesContext) { // remove messages from the context List<FacesMessage> messages = new ArrayList<FacesMessage>(); for(Iterator<FacesMessage> i = facesContext.getMessages(null); i.hasNext(); ) { messages.add(i.next()); i.remove(); } // store them in the session if(messages.size() == 0) { return 0; } Map<String, Object> sessionMap = facesContext.getExternalContext().getSessionMap(); // if there already are messages @SuppressWarnings("unchecked") List<FacesMessage> existingMessages = (List<FacesMessage>) sessionMap.get(sessionToken); if(existingMessages != null) { existingMessages.addAll(messages); } else { sessionMap.put(sessionToken, messages); // if these are the first messages } return messages.size(); }
Example 3
Source File: JSFUtils.java From development with Apache License 2.0 | 6 votes |
public static boolean replaceMessageInListIfExisting(String oldKey, Object[] oldParams, String newKey, Object[] newParams) { FacesContext fc = FacesContext.getCurrentInstance(); String oldText = JSFUtils.getText(oldKey, oldParams); String newText = JSFUtils.getText(newKey, newParams); for (Iterator<FacesMessage> i = fc.getMessages(); i.hasNext();) { FacesMessage fm = i.next(); if (fm.getDetail().equals(oldText)) { fm.setDetail(newText); fm.setSummary(newText); return true; } } return false; }
Example 4
Source File: MessageSaver.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Save current messages for later restoration. * * @param context * The current faces context. */ public static void saveMessages(FacesContext context) { if (context == null) return; // look in the session HttpSession s = (HttpSession) context.getExternalContext().getSession(false); if (s == null) return; // collect the messages from the context for restoration on the next rendering List msgs = new Vector(); for (Iterator iMessages = context.getMessages(); iMessages.hasNext();) { FacesMessage msg = (FacesMessage) iMessages.next(); msgs.add(msg); } // store the messages for this mode to find s.setAttribute(ATTR_MSGS, msgs); }
Example 5
Source File: MessageSaver.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Save current messages for later restoration. * * @param context * The current faces context. */ public static void saveMessages(FacesContext context) { if (context == null) return; // look in the session HttpSession s = (HttpSession) context.getExternalContext().getSession(false); if (s == null) return; // collect the messages from the context for restoration on the next rendering List msgs = new Vector(); for (Iterator iMessages = context.getMessages(); iMessages.hasNext();) { FacesMessage msg = (FacesMessage) iMessages.next(); msgs.add(msg); } // store the messages for this mode to find s.setAttribute(ATTR_MSGS, msgs); }
Example 6
Source File: MessageHandler.java From ee8-sandbox with Apache License 2.0 | 6 votes |
/** * Remove the messages that are not associated with any particular component * from the faces context and store them to the user's session. * * @return the number of removed messages. */ private int saveMessages(FacesContext facesContext) { // remove messages from the context List<FacesMessage> messages = new ArrayList<FacesMessage>(); for(Iterator<FacesMessage> i = facesContext.getMessages(null); i.hasNext(); ) { messages.add(i.next()); i.remove(); } // store them in the session if(messages.size() == 0) { return 0; } Map<String, Object> sessionMap = facesContext.getExternalContext().getSessionMap(); // if there already are messages @SuppressWarnings("unchecked") List<FacesMessage> existingMessages = (List<FacesMessage>) sessionMap.get(sessionToken); if(existingMessages != null) { existingMessages.addAll(messages); } else { sessionMap.put(sessionToken, messages); // if these are the first messages } return messages.size(); }
Example 7
Source File: MessageHandler.java From ee8-sandbox with Apache License 2.0 | 6 votes |
/** * Remove the messages that are not associated with any particular component * from the faces context and store them to the user's session. * * @return the number of removed messages. */ private int saveMessages(FacesContext facesContext) { // remove messages from the context List<FacesMessage> messages = new ArrayList<FacesMessage>(); for(Iterator<FacesMessage> i = facesContext.getMessages(null); i.hasNext(); ) { messages.add(i.next()); i.remove(); } // store them in the session if(messages.size() == 0) { return 0; } Map<String, Object> sessionMap = facesContext.getExternalContext().getSessionMap(); // if there already are messages @SuppressWarnings("unchecked") List<FacesMessage> existingMessages = (List<FacesMessage>) sessionMap.get(sessionToken); if(existingMessages != null) { existingMessages.addAll(messages); } else { sessionMap.put(sessionToken, messages); // if these are the first messages } return messages.size(); }
Example 8
Source File: MessageHandler.java From ee8-sandbox with Apache License 2.0 | 6 votes |
/** * Remove the messages that are not associated with any particular component * from the faces context and store them to the user's session. * * @return the number of removed messages. */ private int saveMessages(FacesContext facesContext) { // remove messages from the context List<FacesMessage> messages = new ArrayList<FacesMessage>(); for(Iterator<FacesMessage> i = facesContext.getMessages(null); i.hasNext(); ) { messages.add(i.next()); i.remove(); } // store them in the session if(messages.size() == 0) { return 0; } Map<String, Object> sessionMap = facesContext.getExternalContext().getSessionMap(); // if there already are messages @SuppressWarnings("unchecked") List<FacesMessage> existingMessages = (List<FacesMessage>) sessionMap.get(sessionToken); if(existingMessages != null) { existingMessages.addAll(messages); } else { sessionMap.put(sessionToken, messages); // if these are the first messages } return messages.size(); }
Example 9
Source File: MessageHandler.java From ee8-sandbox with Apache License 2.0 | 6 votes |
/** * Remove the messages that are not associated with any particular component * from the faces context and store them to the user's session. * * @return the number of removed messages. */ private int saveMessages(FacesContext facesContext) { // remove messages from the context List<FacesMessage> messages = new ArrayList<FacesMessage>(); for(Iterator<FacesMessage> i = facesContext.getMessages(null); i.hasNext(); ) { messages.add(i.next()); i.remove(); } // store them in the session if(messages.size() == 0) { return 0; } Map<String, Object> sessionMap = facesContext.getExternalContext().getSessionMap(); // if there already are messages @SuppressWarnings("unchecked") List<FacesMessage> existingMessages = (List<FacesMessage>) sessionMap.get(sessionToken); if(existingMessages != null) { existingMessages.addAll(messages); } else { sessionMap.put(sessionToken, messages); // if these are the first messages } return messages.size(); }
Example 10
Source File: MessageHandler.java From ee8-sandbox with Apache License 2.0 | 6 votes |
/** * Remove the messages that are not associated with any particular component * from the faces context and store them to the user's session. * * @return the number of removed messages. */ private int saveMessages(FacesContext facesContext) { // remove messages from the context List<FacesMessage> messages = new ArrayList<FacesMessage>(); for(Iterator<FacesMessage> i = facesContext.getMessages(null); i.hasNext(); ) { messages.add(i.next()); i.remove(); } // store them in the session if(messages.size() == 0) { return 0; } Map<String, Object> sessionMap = facesContext.getExternalContext().getSessionMap(); // if there already are messages @SuppressWarnings("unchecked") List<FacesMessage> existingMessages = (List<FacesMessage>) sessionMap.get(sessionToken); if(existingMessages != null) { existingMessages.addAll(messages); } else { sessionMap.put(sessionToken, messages); // if these are the first messages } return messages.size(); }
Example 11
Source File: MessageHandler.java From ee7-sandbox with Apache License 2.0 | 6 votes |
/** * Remove the messages that are not associated with any particular component * from the faces context and store them to the user's session. * * @return the number of removed messages. */ private int saveMessages(FacesContext facesContext) { // remove messages from the context List<FacesMessage> messages = new ArrayList<FacesMessage>(); for(Iterator<FacesMessage> i = facesContext.getMessages(null); i.hasNext(); ) { messages.add(i.next()); i.remove(); } // store them in the session if(messages.size() == 0) { return 0; } Map<String, Object> sessionMap = facesContext.getExternalContext().getSessionMap(); // if there already are messages @SuppressWarnings("unchecked") List<FacesMessage> existingMessages = (List<FacesMessage>) sessionMap.get(sessionToken); if(existingMessages != null) { existingMessages.addAll(messages); } else { sessionMap.put(sessionToken, messages); // if these are the first messages } return messages.size(); }
Example 12
Source File: ManageLanguageCtrlTest.java From development with Apache License 2.0 | 5 votes |
private boolean containsMessageInList(FacesContext fc, String msg) { for (Iterator<FacesMessage> i = fc.getMessages(); i.hasNext();) { if (i.next().getDetail().contains(msg)) { return true; } } return false; }
Example 13
Source File: JSFUtils.java From development with Apache License 2.0 | 5 votes |
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 14
Source File: GrowlRenderer.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
@Override public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException { if (!component.isRendered()){ return; } Growl uiGrowl = (Growl) component; ResponseWriter writer = facesContext.getResponseWriter(); String clientId = uiGrowl.getClientId(facesContext); // get the for value String forValue = uiGrowl.getFor(); Iterator<FacesMessage> allMessages = null; if ( uiGrowl.isGlobalOnly() ) { allMessages = facesContext.getMessages(null); } else if(forValue != null && forValue.length() > 0) { forValue = ExpressionResolver.getComponentIDs(facesContext, uiGrowl, forValue); allMessages = facesContext.getMessages(forValue); } else { allMessages = facesContext.getMessages(); } writer.startElement("script", uiGrowl); writer.writeAttribute("id", clientId, "id"); writer.writeText("$(function() { ", null); while (allMessages.hasNext()) { FacesMessage message = allMessages.next(); if (!shouldBeRendered(message, uiGrowl)){ continue; } encodeSeverityMessage(facesContext, uiGrowl, message); message.rendered(); } writer.writeText("});", null); writer.endElement("script"); }
Example 15
Source File: DivMessageRenderer.java From sakai with Educational Community License v2.0 | 5 votes |
public void encodeEnd(FacesContext context, UIComponent component) throws IOException { // Note our complete disregard for class cast and null exceptions.... UIMessage uiMessage = (UIMessage)component; String clientId = uiMessage.findComponent(uiMessage.getFor()).getClientId(context); Iterator iter = context.getMessages(clientId); if (iter.hasNext()) { // Just do the first one. FacesMessage message = (FacesMessage)iter.next(); renderMessage(context, component, message); } }
Example 16
Source File: FacesUtils.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * Clear the messages component on the user screen * * @param context the view context to be used */ public static void clearMessages(FacesContext context) { final Iterator<FacesMessage> messages = context.getMessages(); while (messages.hasNext()) { messages.next(); messages.remove(); } }
Example 17
Source File: FacesUtils.java From web-budget with GNU General Public License v3.0 | 5 votes |
/** * Clear the messages component on the user screen * * @param context the view context to be used */ public static void clearMessages(FacesContext context) { final Iterator<FacesMessage> messages = context.getMessages(); while (messages.hasNext()) { messages.next(); messages.remove(); } }
Example 18
Source File: FacesUtils.java From library with Apache License 2.0 | 5 votes |
/** * Clear the messages component on the user screen * * @param context the view context to be used */ public static void clearMessages(FacesContext context) { final Iterator<FacesMessage> messages = context.getMessages(); while (messages.hasNext()) { messages.next(); messages.remove(); } }
Example 19
Source File: FormTableRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked")//$NON-NLS-1$ protected static Iterator<FacesMessage> getMessages(FacesContext context) { return context.getMessages(); }
Example 20
Source File: FormTableRenderer.java From XPagesExtensionLibrary with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked")//$NON-NLS-1$ protected static Iterator<FacesMessage> getMessages(FacesContext context, String clientId) { return context.getMessages(clientId); }