01: /*
02: * This file is part of the WfMOpen project.
03: * Copyright (C) 2001-2006 Danet GmbH (www.danet.de), BU BTS.
04: * All rights reserved.
05: *
06: * This program is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU General Public License as published by
08: * the Free Software Foundation; either version 2 of the License, or
09: * (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * $Id: RemoveMessagesListener.java,v 1.1 2007/01/15 14:54:23 drmlipp Exp $
21: *
22: * $Log: RemoveMessagesListener.java,v $
23: * Revision 1.1 2007/01/15 14:54:23 drmlipp
24: * Display messages only once.
25: *
26: */
27: package de.danet.an.util.jsf;
28:
29: import java.util.Iterator;
30:
31: import javax.faces.context.FacesContext;
32: import javax.faces.event.PhaseEvent;
33: import javax.faces.event.PhaseId;
34: import javax.faces.event.PhaseListener;
35:
36: /**
37: * This class provides a phase listener that removes all queued messages at
38: * the end of the rendering phase. Normally, the message queue is cleared at
39: * the start of the lifecycle. In a portlet context, however, the rendering
40: * phase may be invoked repeatedly and messages will be redisplayed.
41: * Especially in the case of error messages, it may be desirable to clear the
42: * messages after a single display. If you want this behaviour, configure this
43: * listener.
44: *
45: * @author Michael Lipp
46: *
47: */
48: public class RemoveMessagesListener implements PhaseListener {
49:
50: /* (non-Javadoc)
51: * @see javax.faces.event.PhaseListener#afterPhase
52: */
53: public void afterPhase(PhaseEvent arg0) {
54: Iterator msgs = FacesContext.getCurrentInstance().getMessages();
55: while (msgs.hasNext()) {
56: msgs.next();
57: msgs.remove();
58: }
59: }
60:
61: /* (non-Javadoc)
62: * @see javax.faces.event.PhaseListener#beforePhase
63: */
64: public void beforePhase(PhaseEvent arg0) {
65: }
66:
67: /* (non-Javadoc)
68: * @see javax.faces.event.PhaseListener#getPhaseId()
69: */
70: public PhaseId getPhaseId() {
71: return PhaseId.RENDER_RESPONSE;
72: }
73:
74: }
|