Author: craigmcc
Date: Sun Apr 17 23:06:48 2005
New Revision: 161737

URL: http://svn.apache.org/viewcvs?view=rev&rev=161737
Log:
Add "AbstractFacesBean" as a general purpose abstract base class for
application classes that want to interact with JavaServer Faces capabilities.
Make AbstractViewController extend AbstractFacesBean so that all of these
capabilities are made available.

Added:
    
struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractFacesBean.java
Modified:
    
struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractViewController.java

Added: 
struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractFacesBean.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractFacesBean.java?view=auto&rev=161737
==============================================================================
--- 
struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractFacesBean.java
 (added)
+++ 
struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractFacesBean.java
 Sun Apr 17 23:06:48 2005
@@ -0,0 +1,301 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.view;
+
+import java.util.Map;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+/**
+ * <p>Convenient abstract base class for application beans that wish to
+ * interact with JavaServer Faces request processing facilities.
+ * <strong>WARNING</strong> - These methods are only effective during
+ * the lifecycle of a JavaServer Faces request.</p>
+ *
+ * $Id$
+ */
+public abstract class AbstractFacesBean {
+    
+
+    // -------------------------------- JavaServer Faces Object Accessor 
Methods
+
+
+    /**
+     * <p>Retiurn the <code>Application</code> instance for the current
+     * web application.</p>
+     */
+    protected Application getApplication() {
+
+        return FacesContext.getCurrentInstance().getApplication();
+
+    }
+
+
+    /**
+     * <p>Return a <code>Map</code> of the application scope attributes
+     * for this web application.</p>
+     */
+    protected Map getApplicationMap() {
+
+        return getExternalContext().getApplicationMap();
+
+    }
+
+
+    /**
+     * <p>Return the <code>ExternalContext</code> instance for the
+     * current request.</p>
+     */
+    protected ExternalContext getExternalContext() {
+
+        return FacesContext.getCurrentInstance().getExternalContext();
+
+    }
+
+
+    /**
+     * <p>Return the <code>FacesContext</code> instance for the
+     * current request.</p>
+     */
+    protected FacesContext getFacesContext() {
+
+        return FacesContext.getCurrentInstance();
+
+    }
+
+
+    /**
+     * <p>Return a <code>Map</code> of the request scope attributes
+     * for this request.</p>
+     */
+    protected Map getRequestMap() {
+
+        return getExternalContext().getRequestMap();
+
+    }
+
+
+    /**
+     * <p>Return a <code>Map</code> of the session scope attributes
+     * for the current user.</p>
+     */
+    protected Map getSessionMap() {
+
+        return getExternalContext().getSessionMap();
+
+    }
+
+
+    // --------------------------------------------------- Bean Accessor 
Methods
+
+
+    /**
+     * <p>Return the named bean from request, session, or application scope.
+     * If this is a managed bean, it might also get created as a side effect.
+     * Return <code>null</code> if no such bean can be found or created.</p>
+     *
+     * @param name Name of the desired bean
+     */
+    protected Object getBean(String name) {
+
+        FacesContext context = getFacesContext();
+        return context.getApplication().getVariableResolver().
+          resolveVariable(context, name);
+
+    }
+
+
+    /**
+     * <p>Replace the value of any attribute stored in request scope,
+     * session scope, or application scope, under the specified name.
+     * If there is no such value, store this value as a new request
+     * scope attribute under the specified name.</p>
+     *
+     * @param name Name of the attribute to replace or create
+     * @param value Value to be stored
+     */
+    protected void setBean(String name, Object value) {
+
+        setValue("#{" + name + "}", value);
+
+    }
+
+
+    // -------------------------------------------- Expression Evauation 
Methods
+
+
+    /**
+     * <p>Evaluate the specified value binding expression and return
+     * the value it points at.</p>
+     *
+     * @param expr Value binding expression to be evaluated
+     */
+    protected Object getValue(String expr) {
+
+        ValueBinding vb = getApplication().createValueBinding(expr);
+        return vb.getValue(getFacesContext());
+
+    }
+
+
+    /**
+     * <p>Evaluate the specified value binding expression, and replace
+     * the value it points at.</p>
+     *
+     * @param expr Value binding expression pointing at a writeable property
+     * @param value New value to store there
+     */
+    protected void setValue(String expr, Object value) {
+
+        ValueBinding vb = getApplication().createValueBinding(expr);
+        vb.setValue(getFacesContext(), value);
+
+    }
+
+
+    // --------------------------------------------------------- Message 
Methods
+
+
+    /**
+     * <p>Enqueue a global <code>FacesMessage</code> (not associated with any
+     * particular component) containing the specified summary text and a
+     * message severity level of <code>FacesMessage.SEVERITY_INFO</code>.</p>
+     *
+     * @param summary Summary text for this message
+     */
+    protected void info(String summary) {
+
+        getFacesContext().addMessage(null,
+          new FacesMessage(FacesMessage.SEVERITY_INFO, summary, null));
+
+    }
+
+
+    /**
+     * <p>Enqueue a <code>FacesMessage</code> (associated with the
+     * specified component) containing the specified summary text and a
+     * message severity level of <code>FacesMessage.SEVERITY_INFO</code>.</p>
+     *
+     * @param component Component with which this message is associated
+     * @param summary Summary text for this message
+     */
+    protected void info(UIComponent component, String summary) {
+
+        getFacesContext().addMessage(null,
+          new FacesMessage(FacesMessage.SEVERITY_INFO, summary, null));
+
+    }
+
+
+    /**
+     * <p>Enqueue a global <code>FacesMessage</code> (not associated with any
+     * particular component) containing the specified summary text and a
+     * message severity level of <code>FacesMessage.SEVERITY_WARN</code>.</p>
+     *
+     * @param summary Summary text for this message
+     */
+    protected void warn(String summary) {
+
+        getFacesContext().addMessage(null,
+          new FacesMessage(FacesMessage.SEVERITY_WARN, summary, null));
+
+    }
+
+
+    /**
+     * <p>Enqueue a <code>FacesMessage</code> (associated with the
+     * specified component) containing the specified summary text and a
+     * message severity level of <code>FacesMessage.SEVERITY_WARN</code>.</p>
+     *
+     * @param component Component with which this message is associated
+     * @param summary Summary text for this message
+     */
+    protected void warn(UIComponent component, String summary) {
+
+        getFacesContext().addMessage(null,
+          new FacesMessage(FacesMessage.SEVERITY_WARN, summary, null));
+
+    }
+
+
+    /**
+     * <p>Enqueue a global <code>FacesMessage</code> (not associated with any
+     * particular component) containing the specified summary text and a
+     * message severity level of <code>FacesMessage.SEVERITY_ERROR</code>.</p>
+     *
+     * @param summary Summary text for this message
+     */
+    protected void error(String summary) {
+
+        getFacesContext().addMessage(null,
+          new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, null));
+
+    }
+
+
+    /**
+     * <p>Enqueue a <code>FacesMessage</code> (associated with the
+     * specified component) containing the specified summary text and a
+     * message severity level of <code>FacesMessage.SEVERITY_ERROR</code>.</p>
+     *
+     * @param component Component with which this message is associated
+     * @param summary Summary text for this message
+     */
+    protected void error(UIComponent component, String summary) {
+
+        getFacesContext().addMessage(null,
+          new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, null));
+
+    }
+
+
+    /**
+     * <p>Enqueue a global <code>FacesMessage</code> (not associated with any
+     * particular component) containing the specified summary text and a
+     * message severity level of <code>FacesMessage.SEVERITY_FATAL</code>.</p>
+     *
+     * @param summary Summary text for this message
+     */
+    protected void fatal(String summary) {
+
+        getFacesContext().addMessage(null,
+          new FacesMessage(FacesMessage.SEVERITY_FATAL, summary, null));
+
+    }
+
+
+    /**
+     * <p>Enqueue a <code>FacesMessage</code> (associated with the
+     * specified component) containing the specified summary text and a
+     * message severity level of <code>FacesMessage.SEVERITY_FATAL</code>.</p>
+     *
+     * @param component Component with which this message is associated
+     * @param summary Summary text for this message
+     */
+    protected void fatal(UIComponent component, String summary) {
+
+        getFacesContext().addMessage(null,
+          new FacesMessage(FacesMessage.SEVERITY_FATAL, summary, null));
+
+    }
+
+
+}

Modified: 
struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractViewController.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractViewController.java?view=diff&r1=161736&r2=161737
==============================================================================
--- 
struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractViewController.java
 (original)
+++ 
struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractViewController.java
 Sun Apr 17 23:06:48 2005
@@ -16,16 +16,18 @@
 
 package org.apache.shale.view;
 
-//import org.apache.shale.DialogController;
 import org.apache.shale.ViewController;
 
 /**
- * <p>[EMAIL PROTECTED] AbstractViewController} is a convenience base 
implementation of [EMAIL PROTECTED] ViewController}.</p>
+ * <p>[EMAIL PROTECTED] AbstractViewController} is a convenience base 
implementation of
+ * [EMAIL PROTECTED] ViewController}.  It also provides convenience methods 
inherited
+ * from [EMAIL PROTECTED] AbstractFacesBean} to all of its subclasses.</p>
  *
  * $Id$
  */
 
-public class AbstractViewController implements ViewController {
+public class AbstractViewController extends AbstractFacesBean
+    implements ViewController {
     
 
     // -------------------------------------------------------------- 
Properties



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to