AbstractBacking xref

View Javadoc

    1   /*
    2    * $Id: AbstractBacking.java 471754 2006-11-06 14:55:09Z husted $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *  http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    20   */
    21
    22
    23  package org.apache.struts.webapp.example;
    24
    25
    26  import java.io.IOException;
    27  import javax.faces.FacesException;
    28  import javax.faces.context.FacesContext;
    29
    30
    31  /**
    32   * <p>Abstract base class for backing beans.</p>
    33   */
    34
    35  abstract class AbstractBacking {
    36
    37
    38      // ------------------------------------------------------- Protected Methods
    39
    40
    41      /**
    42       * <p>Return the context relative path for the specified action.</p>
    43       *
    44       * @param context <code>FacesContext</code> for the current request
    45       * @param action Name of the requested action
    46       */
    47      protected StringBuffer action(FacesContext context, String action) {
    48
    49          // FIXME - assumes extension mapping for Struts
    50          StringBuffer sb = new StringBuffer(action);
    51          sb.append(".do");
    52          return (sb);
    53
    54      }
    55
    56
    57      /**
    58       * <p>Forward to the specified URL and mark this response as having
    59       * been completed.</p>
    60       *
    61       * @param context <code>FacesContext</code> for the current request
    62       * @param url Context-relative URL to forward to
    63       *
    64       * @exception FacesException if any error occurs
    65       */
    66      protected void forward(FacesContext context, String url) {
    67
    68          try {
    69              context.getExternalContext().dispatch(url);
    70          } catch (IOException e) {
    71              throw new FacesException(e);
    72          } finally {
    73              context.responseComplete();
    74          }
    75
    76      }
    77
    78
    79      /**
    80       * <p>Return the context relative base URL for the "logoff"
    81       * action.</p>
    82       *
    83       * @param context <code>FacesContext</code> for the current request
    84       */
    85      protected StringBuffer logoff(FacesContext context) {
    86
    87          return (action(context, "/logoff"));
    88
    89      }
    90
    91
    92      /**
    93       * <p>Return the context relative base URL for the "logon"
    94       * action.</p>
    95       *
    96       * @param context <code>FacesContext</code> for the current request
    97       */
    98      protected StringBuffer logon(FacesContext context) {
    99
    100         return (action(context, "/logon"));
    101
    102     }
    103
    104
    105     /**
    106      * <p>Return the context relative base URL for the "edit registration"
    107      * action.</p>
    108      *
    109      * @param context <code>FacesContext</code> for the current request
    110      */
    111     protected StringBuffer registration(FacesContext context) {
    112
    113         return (action(context, "/editRegistration"));
    114
    115     }
    116
    117
    118     /**
    119      * <p>Return the context relative base URL for the "edit subscriptions"
    120      * action.</p>
    121      *
    122      * @param context <code>FacesContext</code> for the current request
    123      */
    124     protected StringBuffer subscription(FacesContext context) {
    125
    126         return (action(context, "/editSubscription"));
    127
    128     }
    129
    130
    131 }