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