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 org.apache.myfaces.shared_orchestra.renderkit.JSFAttr;
    22  import org.apache.myfaces.shared_orchestra.renderkit.RendererUtils;
    23
    24  import javax.faces.component.UIComponent;
    25  import javax.faces.component.UIOutput;
    26  import javax.faces.component.UIInput;
    27  import javax.faces.component.html.HtmlInputSecret;
    28  import javax.faces.context.FacesContext;
    29  import javax.faces.context.ResponseWriter;
    30  import javax.faces.convert.ConverterException;
    31  import java.io.IOException;
    32
    33
    34  /**
    35   * see Spec.1.0 EA - JSF.7.6.4 Renderer Types for UIInput Components
    36   * @author Manfred Geiler (latest modification by $Author: grantsmith $)
    37   * @author Thomas Spiegl
    38   * @author Anton Koinov
    39   * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Wed, 08 Nov 2006) $
    40   */
    41  public class HtmlSecretRendererBase
    42          extends HtmlRenderer
    43  {
    44      public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
    45              throws IOException
    46      {
    47          RendererUtils.checkParamValidity(facesContext, uiComponent, UIInput.class);
    48
    49          ResponseWriter writer = facesContext.getResponseWriter();
    50          writer.startElement(HTML.INPUT_ELEM, uiComponent);
    51          writer.writeAttribute(HTML.TYPE_ATTR, org.apache.myfaces.shared_orchestra.renderkit.html.HTML.INPUT_TYPE_PASSWORD, null);
    52
    53          String clientId = uiComponent.getClientId(facesContext);
    54
    55          HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
    56          writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
    57
    58          boolean isRedisplay;
    59          if (uiComponent instanceof HtmlInputSecret)
    60          {
    61              isRedisplay = ((HtmlInputSecret)uiComponent).isRedisplay();
    62          }
    63          else
    64          {
    65              isRedisplay = org.apache.myfaces.shared_orchestra.renderkit.RendererUtils.getBooleanAttribute(uiComponent, JSFAttr.REDISPLAY_ATTR, false);
    66          }
    67          if (isRedisplay)
    68          {
    69              String strValue = RendererUtils.getStringValue(facesContext, uiComponent);
    70              writer.writeAttribute(HTML.VALUE_ATTR, strValue, JSFAttr.VALUE_ATTR);
    71          }
    72
    73          HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
    74          if (isDisabled(facesContext, uiComponent))
    75          {
    76              writer.writeAttribute(HTML.DISABLED_ATTR, Boolean.TRUE, null);
    77          }
    78
    79          writer.endElement(HTML.INPUT_ELEM);
    80      }
    81
    82
    83      protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent)
    84      {
    85          //TODO: overwrite in extended HtmlSecretRenderer and check for enabledOnUserRole
    86          if (uiComponent instanceof HtmlInputSecret)
    87          {
    88              return ((HtmlInputSecret)uiComponent).isDisabled();
    89          }
    90          else
    91          {
    92              return RendererUtils.getBooleanAttribute(uiComponent, HTML.DISABLED_ATTR, false);
    93          }
    94      }
    95
    96
    97      public void decode(FacesContext facesContext, UIComponent component)
    98      {
    99          org.apache.myfaces.shared_orchestra.renderkit.RendererUtils.checkParamValidity(facesContext, component, UIInput.class);
    100         HtmlRendererUtils.decodeUIInput(facesContext, component);
    101     }
    102
    103     public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException
    104     {
    105         RendererUtils.checkParamValidity(facesContext, uiComponent, UIOutput.class);
    106         return RendererUtils.getConvertedUIOutputValue(facesContext,
    107                                                        (UIOutput)uiComponent,
    108                                                        submittedValue);
    109     }
    110
    111 }