org.mentawai.message.MessageManager Maven / Gradle / Ivy
/*
* Mentawai Web Framework http://mentawai.lohis.com.br/
* Copyright (C) 2005 Sergio Oliveira Jr. ([email protected])
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.mentawai.message;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.mentawai.core.Action;
import org.mentawai.core.Context;
import org.mentawai.core.Output;
import org.mentawai.filter.FlashScopeFilter;
/**
* @author Sergio Oliveira
*/
public class MessageManager {
public static String ERRORS = "_errors";
public static String MESSAGES = "_messages";
public static String FIELDERRORS = "_fieldErrors";
public static List getErrors(Action action, boolean create) {
if (action == null) return null;
Output output = action.getOutput();
List errors = (List) output.getValue(ERRORS);
if (errors == null && create) {
errors = new LinkedList();
output.setValue(ERRORS, errors);
}
return errors;
}
public static Map getFieldErrors(Action action, boolean create) {
if (action == null) return null;
Output output = action.getOutput();
Map fieldErrors = (Map) output.getValue(FIELDERRORS);
if (fieldErrors == null && create) {
fieldErrors = new LinkedHashMap();
output.setValue(FIELDERRORS, fieldErrors);
}
return fieldErrors;
}
public static List getMessages(Action action, boolean create, boolean flash) {
if (action == null) return null;
Output output = action.getOutput();
List messages = (List) output.getValue(MESSAGES);
if (messages == null && create) {
messages = new LinkedList();
output.setValue(MESSAGES, messages);
if (flash) {
Context session = action.getSession();
session.setAttribute(FlashScopeFilter.KEY + "." + MESSAGES, messages);
}
}
return messages;
}
public static List getMessages(Action action, boolean create) {
return getMessages(action, create, false);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy