View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
    10   *   http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing,
    13   * software distributed under the License is distributed on an
    14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    15   * KIND, either express or implied.  See the License for the
    16   * specific language governing permissions and limitations
    17   * under the License.
    18   */
    19  package org.apache.myfaces.shared_orchestra.renderkit.html;
    20
    21  import java.io.IOException;
    22
    23  import org.apache.myfaces.shared_orchestra.renderkit.RendererUtils;
    24  import org.apache.myfaces.shared_orchestra.config.MyfacesConfig;
    25
    26  import javax.faces.component.UIComponent;
    27  import javax.faces.component.UISelectMany;
    28  import javax.faces.component.UISelectOne;
    29  import javax.faces.component.html.HtmlSelectManyMenu;
    30  import javax.faces.component.html.HtmlSelectOneMenu;
    31  import javax.faces.context.FacesContext;
    32  import javax.faces.convert.ConverterException;
    33
    34  /**
    35   * X-CHECKED: tlddoc of h:selectManyListbox
    36   *
    37   * @author Manfred Geiler (latest modification by $Author: skitching $)
    38   * @author Thomas Spiegl
    39   * @version $Revision: 673826 $ $Date: 2008-07-03 16:43:52 -0500 (Thu, 03 Jul 2008) $
    40   */
    41  public class HtmlMenuRendererBase
    42          extends HtmlRenderer
    43  {
    44      //private static final Log log = LogFactory.getLog(HtmlMenuRenderer.class);
    45
    46      public void encodeEnd(FacesContext facesContext, UIComponent component)
    47              throws IOException
    48      {
    49          RendererUtils.checkParamValidity(facesContext, component, null);
    50
    51          if (component instanceof UISelectMany)
    52          {
    53              HtmlRendererUtils.renderMenu(facesContext,
    54                                           (UISelectMany)component,
    55                                           isDisabled(facesContext, component));
    56          }
    57          else if (component instanceof UISelectOne)
    58          {
    59              HtmlRendererUtils.renderMenu(facesContext,
    60                                           (UISelectOne)component,
    61                                           isDisabled(facesContext, component));
    62          }
    63          else
    64          {
    65              throw new IllegalArgumentException("Unsupported component class " + component.getClass().getName());
    66          }
    67      }
    68
    69      protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent)
    70      {
    71          //TODO: overwrite in extended HtmlMenuRenderer and check for enabledOnUserRole
    72          boolean disabled;
    73          boolean readonly;
    74          if (uiComponent instanceof HtmlSelectManyMenu)
    75          {
    76              disabled = ((HtmlSelectManyMenu)uiComponent).isDisabled();
    77              readonly = ((HtmlSelectManyMenu)uiComponent).isReadonly();
    78          }
    79          else if (uiComponent instanceof HtmlSelectOneMenu)
    80          {
    81              disabled = ((HtmlSelectOneMenu)uiComponent).isDisabled();
    82              readonly = ((HtmlSelectOneMenu)uiComponent).isReadonly();
    83          }
    84          else
    85          {
    86              disabled = RendererUtils.getBooleanAttribute(uiComponent, HTML.DISABLED_ATTR, false);
    87              readonly = RendererUtils.getBooleanAttribute(uiComponent, HTML.READONLY_ATTR, false);
    88          }
    89          if (!disabled && readonly) {
    90              disabled = MyfacesConfig.getCurrentInstance(facesContext
    91                              .getExternalContext()).isReadonlyAsDisabledForSelect();
    92          }
    93          return disabled;
    94      }
    95
    96      public void decode(FacesContext facesContext, UIComponent uiComponent)
    97      {
    98          org.apache.myfaces.shared_orchestra.renderkit.RendererUtils.checkParamValidity(facesContext, uiComponent, null);
    99
    100         if (uiComponent instanceof UISelectMany)
    101         {
    102             HtmlRendererUtils.decodeUISelectMany(facesContext, uiComponent);
    103         }
    104         else if (uiComponent instanceof UISelectOne)
    105         {
    106             HtmlRendererUtils.decodeUISelectOne(facesContext, uiComponent);
    107         }
    108         else
    109         {
    110             throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
    111         }
    112     }
    113
    114     public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException
    115     {
    116         org.apache.myfaces.shared_orchestra.renderkit.RendererUtils.checkParamValidity(facesContext, uiComponent, null);
    117
    118         if (uiComponent instanceof UISelectMany)
    119         {
    120             return org.apache.myfaces.shared_orchestra.renderkit.RendererUtils.getConvertedUISelectManyValue(facesContext,
    121                                                                (UISelectMany)uiComponent,
    122                                                                submittedValue);
    123         }
    124         else if (uiComponent instanceof UISelectOne)
    125         {
    126             return org.apache.myfaces.shared_orchestra.renderkit.RendererUtils.getConvertedUIOutputValue(facesContext,
    127                                                            (UISelectOne)uiComponent,
    128                                                            submittedValue);
    129         }
    130         else
    131         {
    132             throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
    133         }
    134     }
    135
    136 }