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