Java Code Examples for org.apache.struts.Globals#ERROR_KEY

The following examples show how to use org.apache.struts.Globals#ERROR_KEY . 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: StrutsDelegate.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add messages to the request
 * @param request Request where messages will be saved.
 * @param messages Messages to be saved.
 */
// TODO Write unit tests for saveMessages(HttpServletRequest, ActionMessages)
public void saveMessages(HttpServletRequest request, ActionMessages messages) {
    HttpSession session = request.getSession();

    if ((messages == null) || messages.isEmpty()) {
        session.removeAttribute(Globals.ERROR_KEY);
        session.removeAttribute(Globals.MESSAGE_KEY);
        return;
    }
    String key = Globals.MESSAGE_KEY;
    if (messages instanceof ActionErrors) {
        key = Globals.ERROR_KEY;
    }

    ActionMessages newMessages = new ActionMessages();

    // Check for existing messages
    ActionMessages sessionExisting =
        (ActionMessages) session.getAttribute(key);

    if (sessionExisting != null) {
        newMessages.add(sessionExisting);
    }
    newMessages.add(messages);

    session.setAttribute(key, newMessages);
    request.setAttribute(key, newMessages);
}
 
Example 2
Source File: StrutsDelegate.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add messages to the request
 * @param request Request where messages will be saved.
 * @param messages Messages to be saved.
 */
// TODO Write unit tests for saveMessages(HttpServletRequest, ActionMessages)
public void saveMessages(HttpServletRequest request, ActionMessages messages) {
    HttpSession session = request.getSession();

    if ((messages == null) || messages.isEmpty()) {
        session.removeAttribute(Globals.ERROR_KEY);
        session.removeAttribute(Globals.MESSAGE_KEY);
        return;
    }
    String key = Globals.MESSAGE_KEY;
    if (messages instanceof ActionErrors) {
        key = Globals.ERROR_KEY;
    }

    ActionMessages newMessages = new ActionMessages();

    // Check for existing messages
    ActionMessages sessionExisting =
        (ActionMessages) session.getAttribute(key);

    if (sessionExisting != null) {
        newMessages.add(sessionExisting);
    }
    newMessages.add(messages);

    session.setAttribute(key, newMessages);
    request.setAttribute(key, newMessages);
}