01: /**********************************************************************************
02: *
03: * $Id: InitializableBean.java 9271 2006-05-10 21:52:49Z ray@media.berkeley.edu $
04: *
05: ***********************************************************************************
06: *
07: * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
08: *
09: * Licensed under the Educational Community License, Version 1.0 (the "License");
10: * you may not use this file except in compliance with the License.
11: * You may obtain a copy of the License at
12: *
13: * http://www.opensource.org/licenses/ecl1.php
14: *
15: * Unless required by applicable law or agreed to in writing, software
16: * distributed under the License is distributed on an "AS IS" BASIS,
17: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18: * See the License for the specific language governing permissions and
19: * limitations under the License.
20: *
21: **********************************************************************************/package org.sakaiproject.tool.gradebook.ui;
22:
23: import org.apache.commons.logging.Log;
24: import org.apache.commons.logging.LogFactory;
25: import org.sakaiproject.jsf.model.PhaseAware;
26:
27: public abstract class InitializableBean implements PhaseAware {
28: private static final Log logger = LogFactory
29: .getLog(InitializableBean.class);
30:
31: private transient boolean notValidated;
32:
33: /**
34: * JSF doesn't provide a way to configure an initialization method which will
35: * be called after the contructor and all framework setters. By convention,
36: * our backing beans use this method. It's triggered either by a Faces configuration
37: * file setting "configured" to true, or by a JSF component directly calling "startRenderResponse".
38: *
39: * For greater subclassing flexibility, the init method is not declared to be
40: * abstract.
41: */
42: protected void init() {
43: }
44:
45: /**
46: * Remember if JSF entered the Validations phase. If so, and if we never
47: * reach the Update Model Values phase, then validation failed. That may
48: * be of interest to the backing bean. For example, the backing bean
49: * may choose not to requery and reload data on a validation error.
50: */
51: public void endProcessValidators() {
52: setNotValidated(true);
53: if (logger.isDebugEnabled())
54: logger.debug("endProcessValidators");
55: }
56:
57: public void endProcessUpdates() {
58: setNotValidated(false);
59: if (logger.isDebugEnabled())
60: logger.debug("endProcessUpdates");
61: }
62:
63: /**
64: * Call init() at the beginning of every request rendering.
65: * (This should also work to refresh session-scoped beans, but it's
66: * only been tested with request scope.)
67: */
68: public void startRenderResponse() {
69: if (logger.isDebugEnabled())
70: logger.debug("startRenderResponse notValidated="
71: + isNotValidated());
72: init();
73: }
74:
75: public boolean isNotValidated() {
76: return notValidated;
77: }
78:
79: public void setNotValidated(boolean notValidated) {
80: this .notValidated = notValidated;
81: }
82:
83: /**
84: * Signals that configuration is finished.
85: */
86: public void setConfigured(boolean isConfigured) {
87: if (logger.isDebugEnabled())
88: logger.debug("setConfigured " + isConfigured);
89: if (isConfigured) {
90: init();
91: }
92: }
93:
94: }
|