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 ExtHTML5.forms#the-select-element <select>} 020 * element. 021 * 022 * <ul class='seealso'> 023 * <li class='link'>{@doc DtoHtml5} 024 * </ul> 025 */ 026@Bean(typeName="select") 027public class Select extends HtmlElementContainer { 028 029 /** 030 * Creates an empty {@link Select} element. 031 */ 032 public Select() {} 033 034 /** 035 * Creates a {@link Select} element with the specified {@link Select#name(String)} attribute and child nodes. 036 * 037 * @param name The {@link Select#name(String)} attribute. 038 * @param children The child nodes. 039 */ 040 public Select(String name, Object...children) { 041 name(name).children(children); 042 } 043 044 /** 045 * {@doc ExtHTML5.forms#attr-fe-autofocus autofocus} attribute. 046 * 047 * <p> 048 * Automatically focus the form control when the page is loaded. 049 * 050 * @param autofocus 051 * The new value for this attribute. 052 * Typically a {@link Boolean} or {@link String}. 053 * @return This object (for method chaining). 054 */ 055 public final Select autofocus(Object autofocus) { 056 attr("autofocus", autofocus); 057 return this; 058 } 059 060 /** 061 * {@doc ExtHTML5.forms#attr-fe-disabled disabled} attribute. 062 * 063 * <p> 064 * Whether the form control is disabled. 065 * 066 * @param disabled 067 * The new value for this attribute. 068 * Typically a {@link Boolean} or {@link String}. 069 * @return This object (for method chaining). 070 */ 071 public final Select disabled(Object disabled) { 072 attr("disabled", deminimize(disabled, "disabled")); 073 return this; 074 } 075 076 /** 077 * {@doc ExtHTML5.forms#attr-fae-form form} attribute. 078 * 079 * <p> 080 * Associates the control with a form element. 081 * 082 * @param form The new value for this attribute. 083 * @return This object (for method chaining). 084 */ 085 public final Select form(String form) { 086 attr("form", form); 087 return this; 088 } 089 090 /** 091 * {@doc ExtHTML5.forms#attr-select-multiple multiple} attribute. 092 * 093 * <p> 094 * Whether to allow multiple values. 095 * 096 * @param multiple 097 * The new value for this attribute. 098 * Typically a {@link Boolean} or {@link String}. 099 * @return This object (for method chaining). 100 */ 101 public final Select multiple(Object multiple) { 102 attr("multiple", deminimize(multiple, "multiple")); 103 return this; 104 } 105 106 /** 107 * {@doc ExtHTML5.forms#attr-fe-name name} attribute. 108 * 109 * <p> 110 * Name of form control to use for form submission and in the form.elements API. 111 * 112 * @param name The new value for this attribute. 113 * @return This object (for method chaining). 114 */ 115 public final Select name(String name) { 116 attr("name", name); 117 return this; 118 } 119 120 /** 121 * {@doc ExtHTML5.forms#attr-select-required required} attribute. 122 * 123 * <p> 124 * Whether the control is required for form submission. 125 * 126 * @param required 127 * The new value for this attribute. 128 * Typically a {@link Boolean} or {@link String}. 129 * @return This object (for method chaining). 130 */ 131 public final Select required(Object required) { 132 attr("required", required); 133 return this; 134 } 135 136 /** 137 * {@doc ExtHTML5.forms#attr-select-size size} attribute. 138 * 139 * <p> 140 * Size of the control. 141 * 142 * @param size 143 * The new value for this attribute. 144 * Typically a {@link Number} or {@link String}. 145 * @return This object (for method chaining). 146 */ 147 public final Select size(Object size) { 148 attr("size", size); 149 return this; 150 } 151 152 /** 153 * Convenience method for selecting a child {@link Option} after the options have already been populated. 154 * 155 * @param optionValue The option value. 156 * @return This object (for method chaining). 157 */ 158 public Select choose(Object optionValue) { 159 if (optionValue != null) { 160 for (Object o : getChildren()) { 161 if (o instanceof Option) { 162 Option o2 = (Option)o; 163 if (StringUtils.isEquals(optionValue.toString(), o2.getAttr(String.class, "value"))) 164 o2.selected(true); 165 } 166 } 167 } 168 return this; 169 } 170 171 //----------------------------------------------------------------------------------------------------------------- 172 // Overridden methods 173 //----------------------------------------------------------------------------------------------------------------- 174 175 @Override /* HtmlElement */ 176 public final Select _class(String _class) { 177 super._class(_class); 178 return this; 179 } 180 181 @Override /* HtmlElement */ 182 public final Select id(String id) { 183 super.id(id); 184 return this; 185 } 186 187 @Override /* HtmlElement */ 188 public final Select style(String style) { 189 super.style(style); 190 return this; 191 } 192 193 @Override /* HtmlElementContainer */ 194 public final Select children(Object...children) { 195 super.children(children); 196 return this; 197 } 198 199 @Override /* HtmlElementContainer */ 200 public final Select child(Object child) { 201 super.child(child); 202 return this; 203 } 204}