001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.dto.html5;
014
015import org.apache.juneau.annotation.*;
016import org.apache.juneau.internal.*;
017
018/**
019 * DTO for an HTML {@doc HTML5.forms#the-select-element <select>}
020 * element.
021 *
022 * <h5 class='section'>See Also:</h5>
023 * <ul class='doctree'>
024 *    <li class='link'>{@doc juneau-dto.HTML5}
025 * </ul>
026 */
027@Bean(typeName="select")
028public class Select extends HtmlElementContainer {
029
030   /**
031    * {@doc HTML5.forms#attr-fe-autofocus autofocus} attribute.
032    *
033    * <p>
034    * Automatically focus the form control when the page is loaded.
035    *
036    * @param autofocus
037    *    The new value for this attribute.
038    *    Typically a {@link Boolean} or {@link String}.
039    * @return This object (for method chaining).
040    */
041   public final Select autofocus(Object autofocus) {
042      attr("autofocus", autofocus);
043      return this;
044   }
045
046   /**
047    * {@doc HTML5.forms#attr-fe-disabled disabled} attribute.
048    *
049    * <p>
050    * Whether the form control is disabled.
051    *
052    * @param disabled
053    *    The new value for this attribute.
054    *    Typically a {@link Boolean} or {@link String}.
055    * @return This object (for method chaining).
056    */
057   public final Select disabled(Object disabled) {
058      attr("disabled", deminimize(disabled, "disabled"));
059      return this;
060   }
061
062   /**
063    * {@doc HTML5.forms#attr-fae-form form} attribute.
064    *
065    * <p>
066    * Associates the control with a form element.
067    *
068    * @param form The new value for this attribute.
069    * @return This object (for method chaining).
070    */
071   public final Select form(String form) {
072      attr("form", form);
073      return this;
074   }
075
076   /**
077    * {@doc HTML5.forms#attr-select-multiple multiple} attribute.
078    *
079    * <p>
080    * Whether to allow multiple values.
081    *
082    * @param multiple
083    *    The new value for this attribute.
084    *    Typically a {@link Boolean} or {@link String}.
085    * @return This object (for method chaining).
086    */
087   public final Select multiple(Object multiple) {
088      attr("multiple", deminimize(multiple, "multiple"));
089      return this;
090   }
091
092   /**
093    * {@doc HTML5.forms#attr-fe-name name} attribute.
094    *
095    * <p>
096    * Name of form control to use for form submission and in the form.elements API.
097    *
098    * @param name The new value for this attribute.
099    * @return This object (for method chaining).
100    */
101   public final Select name(String name) {
102      attr("name", name);
103      return this;
104   }
105
106   /**
107    * {@doc HTML5.forms#attr-select-required required} attribute.
108    *
109    * <p>
110    * Whether the control is required for form submission.
111    *
112    * @param required
113    *    The new value for this attribute.
114    *    Typically a {@link Boolean} or {@link String}.
115    * @return This object (for method chaining).
116    */
117   public final Select required(Object required) {
118      attr("required", required);
119      return this;
120   }
121
122   /**
123    * {@doc HTML5.forms#attr-select-size size} attribute.
124    *
125    * <p>
126    * Size of the control.
127    *
128    * @param size
129    *    The new value for this attribute.
130    *    Typically a {@link Number} or {@link String}.
131    * @return This object (for method chaining).
132    */
133   public final Select size(Object size) {
134      attr("size", size);
135      return this;
136   }
137
138   /**
139    * Convenience method for selecting a child {@link Option} after the options have already been populated.
140    *
141    * @param optionValue The option value.
142    * @return This object (for method chaining).
143    */
144   public Select choose(Object optionValue) {
145      if (optionValue != null) {
146         for (Object o : getChildren()) {
147            if (o instanceof Option) {
148               Option o2 = (Option)o;
149               if (StringUtils.isEquals(optionValue.toString(), o2.getAttr(String.class, "value")))
150                  o2.selected(true);
151            }
152         }
153      }
154      return this;
155   }
156
157   //-----------------------------------------------------------------------------------------------------------------
158   // Overridden methods
159   //-----------------------------------------------------------------------------------------------------------------
160
161   @Override /* HtmlElement */
162   public final Select _class(String _class) {
163      super._class(_class);
164      return this;
165   }
166
167   @Override /* HtmlElement */
168   public final Select id(String id) {
169      super.id(id);
170      return this;
171   }
172
173   @Override /* HtmlElement */
174   public final Select style(String style) {
175      super.style(style);
176      return this;
177   }
178
179   @Override /* HtmlElementContainer */
180   public final Select children(Object...children) {
181      super.children(children);
182      return this;
183   }
184
185   @Override /* HtmlElementContainer */
186   public final Select child(Object child) {
187      super.child(child);
188      return this;
189   }
190}