01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.core.admin.ui;
23:
24: import org.jboss.portal.core.admin.ui.dashboard.DashboardBean;
25:
26: import javax.faces.context.FacesContext;
27: import javax.faces.event.PhaseEvent;
28: import javax.faces.event.PhaseId;
29: import javax.faces.event.PhaseListener;
30:
31: /**
32: * Refresh the beans before JSF performs the render.
33: *
34: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
35: * @version $Revision: 8785 $
36: */
37: public class Refresher implements PhaseListener {
38:
39: /** The serialVersionUID */
40: private static final long serialVersionUID = -5027591744094332498L;
41:
42: public void afterPhase(PhaseEvent phaseEvent) {
43: }
44:
45: public void beforePhase(PhaseEvent phaseEvent) {
46: FacesContext ctx = phaseEvent.getFacesContext();
47:
48: if (phaseEvent.getPhaseId() == PhaseId.RESTORE_VIEW) {
49: refreshFrom(ctx);
50:
51: //
52: DashboardBean dashboard = (DashboardBean) ctx
53: .getApplication()
54: .createValueBinding("#{dashboard}").getValue(ctx);
55: dashboard.actionRefresh();
56: } else if (phaseEvent.getPhaseId() == PhaseId.RENDER_RESPONSE) {
57: refreshFrom(ctx);
58:
59: //
60: DashboardBean dashboard = (DashboardBean) ctx
61: .getApplication()
62: .createValueBinding("#{dashboard}").getValue(ctx);
63: dashboard.renderRefresh();
64: }
65: }
66:
67: private void refreshFrom(FacesContext ctx) {
68: //
69: PortalObjectManagerBean pomgr = (PortalObjectManagerBean) ctx
70: .getApplication().createValueBinding(
71: "#{portalobjectmgr}").getValue(ctx);
72: pomgr.refresh();
73:
74: //
75: PortalObjectManagerBean dashboardmgr = (PortalObjectManagerBean) ctx
76: .getApplication().createValueBinding("#{dashboardmgr}")
77: .getValue(ctx);
78: dashboardmgr.refresh();
79:
80: //
81: InstanceManagerBean instancemgr = (InstanceManagerBean) ctx
82: .getApplication().createValueBinding("#{instancemgr}")
83: .getValue(ctx);
84: instancemgr.refresh();
85:
86: //
87: PortletManagerBean portletmgr = (PortletManagerBean) ctx
88: .getApplication().createValueBinding("#{portletmgr}")
89: .getValue(ctx);
90: portletmgr.refresh();
91: }
92:
93: public PhaseId getPhaseId() {
94: return PhaseId.ANY_PHASE;
95: }
96: }
|