View Javadoc

    1   // ========================================================================
    2   // $Id: Input.java,v 1.3 2004/05/09 20:31:28 gregwilkins Exp $
    3   // Copyright 1996-2004 Mort Bay Consulting Pty. Ltd.
    4   // ------------------------------------------------------------------------
    5   // Licensed under the Apache License, Version 2.0 (the "License");
    6   // you may not use this file except in compliance with the License.
    7   // You may obtain a copy of the License at
    8   // http://www.apache.org/licenses/LICENSE-2.0
    9   // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  // ========================================================================
    15
    16  package org.mortbay.html;
    17
    18  /* -------------------------------------------------------------------- */
    19  /** HTML Form Input Tag.
    20   * <p>
    21   * @see Tag
    22   * @see Form
    23   * @version $Id: Input.java,v 1.3 2004/05/09 20:31:28 gregwilkins Exp $
    24   * @author Greg Wilkins
    25   */
    26  public class Input extends Tag
    27  {
    28      /* ----------------------------------------------------------------- */
    29      /** Input types */
    30      public final static String Text="text";
    31      public final static String Password="password";
    32      public final static String Checkbox="checkbox";
    33      public final static String Radio="radio";
    34      public final static String Submit="submit";
    35      public final static String Reset="reset";
    36      public final static String Hidden="hidden";
    37      public final static String File="file";
    38      public final static String Image="image";
    39
    40      /* ----------------------------------------------------------------- */
    41      public Input(String type,String name)
    42      {
    43          super("input");
    44          attribute("type",type);
    45          attribute("name",name);
    46      }
    47
    48      /* ----------------------------------------------------------------- */
    49      public Input(String type,String name, String value)
    50      {
    51          this(type,name);
    52          attribute("value",value);
    53      }
    54
    55      /* ----------------------------------------------------------------- */
    56      public Input(Image image,String name, String value)
    57      {
    58          super("input");
    59          attribute("type","image");
    60          attribute("name",name);
    61          if (value!=null)
    62              attribute("value",value);
    63          attribute(image.attributes());
    64      }
    65
    66      /* ----------------------------------------------------------------- */
    67      public Input(Image image,String name)
    68      {
    69          super("input");
    70          attribute("type","image");
    71          attribute("name",name);
    72          attribute(image.attributes());
    73      }
    74
    75      /* ----------------------------------------------------------------- */
    76      public Input check()
    77      {
    78          attribute("checked");
    79          return this;
    80      }
    81
    82      /* ----------------------------------------------------------------- */
    83      public Input setSize(int size)
    84      {
    85          size(size);
    86          return this;
    87      }
    88
    89      /* ----------------------------------------------------------------- */
    90      public Input setMaxSize(int size)
    91      {
    92          attribute("maxlength",size);
    93          return this;
    94      }
    95
    96      /* ----------------------------------------------------------------- */
    97      public Input fixed()
    98      {
    99          setMaxSize(size());
    100         return this;
    101     }
    102 }