001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.bean.html5; 018 019import java.net.*; 020 021import org.apache.juneau.*; 022import org.apache.juneau.annotation.*; 023import org.apache.juneau.internal.*; 024 025/** 026 * DTO for an HTML <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#the-button-element"><button></a> 027 * element. 028 * 029 * <p> 030 * The button element represents a clickable button that can be used to submit forms, trigger actions, 031 * or perform other interactive functions. Unlike input elements, buttons can contain rich content 032 * including text, images, and other HTML elements. 033 * 034 * <h5 class='section'>Examples:</h5> 035 * <p class='bcode w800'> 036 * <jc>// Simple submit button</jc> 037 * Button <jv>btn1</jv> = <jsm>button</jsm>().type(<js>"submit"</js>).text(<js>"Submit Form"</js>); 038 * 039 * <jc>// Button with custom styling and click handler</jc> 040 * Button <jv>btn2</jv> = <jsm>button</jsm>() 041 * .type(<js>"button"</js>) 042 * ._class(<js>"btn btn-primary"</js>) 043 * .onclick(<js>"handleClick()"</js>) 044 * .text(<js>"Click Me"</js>); 045 * 046 * <jc>// Button with form override attributes</jc> 047 * Button <jv>btn3</jv> = <jsm>button</jsm>() 048 * .type(<js>"submit"</js>) 049 * .formaction(<js>"https://api.example.com/submit"</js>) 050 * .formmethod(<js>"post"</js>) 051 * .formtarget(<js>"_blank"</js>) 052 * .text(<js>"Submit to API"</js>); 053 * 054 * <jc>// Button with icon and text</jc> 055 * Button <jv>btn4</jv> = <jsm>button</jsm>() 056 * .type(<js>"button"</js>) 057 * .children( 058 * <jsm>span</jsm>()._class(<js>"icon"</js>).text(<js>"📧"</js>), 059 * <jsm>span</jsm>().text(<js>"Send Email"</js>) 060 * ); 061 * </p> 062 * 063 * <p> 064 * The following convenience methods are provided for constructing instances of this bean: 065 * <ul class='javatree'> 066 * <li class='jc'>{@link HtmlBuilder} 067 * <ul class='javatree'> 068 * <li class='jm'>{@link HtmlBuilder#button() button()} 069 * <li class='jm'>{@link HtmlBuilder#button(Object, Object...) button(Object, Object...)} 070 * </ul> 071 * </ul> 072 * </p> 073 * 074 * <h5 class='section'>See Also:</h5><ul> 075 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a> 076 * </ul> 077 */ 078@Bean(typeName="button") 079public class Button extends HtmlElementMixed { 080 081 /** 082 * Creates an empty {@link Button} element. 083 */ 084 public Button() {} 085 086 /** 087 * Creates a {@link Button} element with the specified {@link Button#type(String)} attribute. 088 * 089 * @param type The {@link Button#type(String)} attribute. 090 */ 091 public Button(String type) { 092 type(type); 093 } 094 095 /** 096 * Creates a {@link Button} element with the specified {@link Button#type(String)} attribute and 097 * {@link Button#children(Object[])} nodes. 098 * 099 * @param type The {@link Button#type(String)} attribute. 100 * @param children The {@link Button#children(Object[])} nodes. 101 */ 102 public Button(String type, Object...children) { 103 type(type).children(children); 104 } 105 106 /** 107 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fe-autofocus">autofocus</a> attribute. 108 * 109 * <p> 110 * Automatically focus the form control when the page is loaded. 111 * 112 * @param autofocus 113 * The new value for this attribute. 114 * Typically a {@link Boolean} or {@link String}. 115 * @return This object. 116 */ 117 public Button autofocus(Object value) { 118 attr("autofocus", value); 119 return this; 120 } 121 122 /** 123 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fe-disabled">disabled</a> attribute. 124 * 125 * <p> 126 * Whether the form control is disabled. 127 * 128 * <p> 129 * This attribute uses deminimized values: 130 * <ul> 131 * <li><jk>false</jk> - Attribute is not added</li> 132 * <li><jk>true</jk> - Attribute is added as <js>"disabled"</js></li> 133 * <li>Other values - Passed through as-is</li> 134 * </ul> 135 * 136 * @param disabled 137 * The new value for this attribute. 138 * Typically a {@link Boolean} or {@link String}. 139 * @return This object. 140 */ 141 public Button disabled(Object value) { 142 attr("disabled", deminimize(value, "disabled")); 143 return this; 144 } 145 146 /** 147 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fae-form">form</a> attribute. 148 * 149 * <p> 150 * Associates the button with a form element by specifying the form's ID. This allows the button 151 * to be placed outside the form element while still being part of the form submission. 152 * 153 * <p> 154 * The value should match the ID of a form element in the same document. 155 * 156 * @param form The ID of the form element to associate with this button. 157 * @return This object. 158 */ 159 public Button form(String value) { 160 attr("form", value); 161 return this; 162 } 163 164 /** 165 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fs-formaction">formaction</a> attribute. 166 * 167 * <p> 168 * Specifies the URL where the form data will be submitted when this button is clicked. 169 * Overrides the form's action attribute. 170 * 171 * <p> 172 * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}. 173 * Strings must be valid URIs. 174 * 175 * <p> 176 * URIs defined by {@link UriResolver} can be used for values. 177 * 178 * @param formaction The URL where the form data will be submitted. 179 * @return This object. 180 */ 181 public Button formaction(String value) { 182 attrUri("formaction", value); 183 return this; 184 } 185 186 /** 187 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fs-formenctype">formenctype</a> attribute. 188 * 189 * <p> 190 * Specifies how form data should be encoded when submitted. Overrides the form's enctype attribute. 191 * 192 * <p> 193 * Possible values: 194 * <ul> 195 * <li><js>"application/x-www-form-urlencoded"</js> - Default encoding (default)</li> 196 * <li><js>"multipart/form-data"</js> - For file uploads</li> 197 * <li><js>"text/plain"</js> - Plain text encoding</li> 198 * </ul> 199 * 200 * @param formenctype The encoding type for form submission. 201 * @return This object. 202 */ 203 public Button formenctype(String value) { 204 attr("formenctype", value); 205 return this; 206 } 207 208 /** 209 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fs-formmethod">formmethod</a> attribute. 210 * 211 * <p> 212 * Specifies the HTTP method to use for form submission. Overrides the form's method attribute. 213 * 214 * <p> 215 * Possible values: 216 * <ul> 217 * <li><js>"get"</js> - Form data is sent as URL parameters</li> 218 * <li><js>"post"</js> - Form data is sent in the request body (default)</li> 219 * <li><js>"dialog"</js> - Used for forms within dialog elements</li> 220 * </ul> 221 * 222 * @param formmethod The HTTP method for form submission. 223 * @return This object. 224 */ 225 public Button formmethod(String value) { 226 attr("formmethod", value); 227 return this; 228 } 229 230 /** 231 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fs-formnovalidate">formnovalidate</a> 232 * attribute. 233 * 234 * <p> 235 * Specifies that form validation should be bypassed when this button submits the form. 236 * Overrides the form's novalidate attribute. 237 * 238 * <p> 239 * This attribute uses deminimized values: 240 * <ul> 241 * <li><jk>false</jk> - Form validation is performed (default)</li> 242 * <li><jk>true</jk> - Form validation is bypassed</li> 243 * <li>Other values - Passed through as-is</li> 244 * </ul> 245 * 246 * @param formnovalidate Whether to bypass form validation. 247 * @return This object. 248 */ 249 public Button formnovalidate(String value) { 250 attr("formnovalidate", value); 251 return this; 252 } 253 254 /** 255 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fs-formtarget">formtarget</a> attribute. 256 * 257 * <p> 258 * Specifies where to display the form response after submission. Overrides the form's target attribute. 259 * 260 * <p> 261 * Common values: 262 * <ul> 263 * <li><js>"_blank"</js> - Open in a new window/tab</li> 264 * <li><js>"_self"</js> - Open in the same frame (default)</li> 265 * <li><js>"_parent"</js> - Open in the parent frame</li> 266 * <li><js>"_top"</js> - Open in the full body of the window</li> 267 * <li><js>"framename"</js> - Open in a named frame</li> 268 * </ul> 269 * 270 * @param formtarget Where to display the form response. 271 * @return This object. 272 */ 273 public Button formtarget(String value) { 274 attr("formtarget", value); 275 return this; 276 } 277 278 /** 279 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fs-menu">menu</a> attribute. 280 * 281 * <p> 282 * Specifies the ID of a menu element that should be displayed as a pop-up menu 283 * when the button is activated. 284 * 285 * <p> 286 * The value should match the ID of a menu element in the same document. 287 * 288 * @param menu The ID of the menu element to display as a pop-up. 289 * @return This object. 290 */ 291 public Button menu(String value) { 292 attr("menu", value); 293 return this; 294 } 295 296 /** 297 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fe-name">name</a> attribute. 298 * 299 * <p> 300 * Specifies the name of the button. This name is used when the form is submitted and 301 * can be used to access the element via the form.elements API. 302 * 303 * <p> 304 * The name should be unique within the form and should not contain spaces or special characters. 305 * 306 * @param name The name of the button for submission and API access. 307 * @return This object. 308 */ 309 public Button name(String value) { 310 attr("name", value); 311 return this; 312 } 313 314 /** 315 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-button-type">type</a> attribute. 316 * 317 * <p> 318 * Specifies the type of button and its behavior when clicked. 319 * 320 * <p> 321 * Possible values: 322 * <ul> 323 * <li><js>"submit"</js> - Submits the form (default)</li> 324 * <li><js>"reset"</js> - Resets the form to its initial state</li> 325 * <li><js>"button"</js> - Generic button with no default behavior</li> 326 * </ul> 327 * 328 * @param type The type of button and its behavior. 329 * @return This object. 330 */ 331 public Button type(String value) { 332 attr("type", value); 333 return this; 334 } 335 336 /** 337 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-button-value">value</a> attribute. 338 * 339 * <p> 340 * Value to be used for form submission. 341 * 342 * @param value 343 * The new value for this attribute. 344 * Typically a {@link Number} or {@link String}. 345 * @return This object. 346 */ 347 public Button value(Object value) { 348 attr("value", value); 349 return this; 350 } 351 352 //----------------------------------------------------------------------------------------------------------------- 353 // Overridden methods 354 //----------------------------------------------------------------------------------------------------------------- 355 @Override /* Overridden from HtmlElement */ 356 public Button _class(String value) { // NOSONAR - Intentional naming. 357 super._class(value); 358 return this; 359 } 360 361 @Override /* Overridden from HtmlElement */ 362 public Button accesskey(String value) { 363 super.accesskey(value); 364 return this; 365 } 366 367 @Override /* Overridden from HtmlElement */ 368 public Button contenteditable(Object value) { 369 super.contenteditable(value); 370 return this; 371 } 372 373 @Override /* Overridden from HtmlElement */ 374 public Button dir(String value) { 375 super.dir(value); 376 return this; 377 } 378 379 @Override /* Overridden from HtmlElement */ 380 public Button hidden(Object value) { 381 super.hidden(value); 382 return this; 383 } 384 385 @Override /* Overridden from HtmlElement */ 386 public Button id(String value) { 387 super.id(value); 388 return this; 389 } 390 391 @Override /* Overridden from HtmlElement */ 392 public Button lang(String value) { 393 super.lang(value); 394 return this; 395 } 396 397 @Override /* Overridden from HtmlElement */ 398 public Button onabort(String value) { 399 super.onabort(value); 400 return this; 401 } 402 403 @Override /* Overridden from HtmlElement */ 404 public Button onblur(String value) { 405 super.onblur(value); 406 return this; 407 } 408 409 @Override /* Overridden from HtmlElement */ 410 public Button oncancel(String value) { 411 super.oncancel(value); 412 return this; 413 } 414 415 @Override /* Overridden from HtmlElement */ 416 public Button oncanplay(String value) { 417 super.oncanplay(value); 418 return this; 419 } 420 421 @Override /* Overridden from HtmlElement */ 422 public Button oncanplaythrough(String value) { 423 super.oncanplaythrough(value); 424 return this; 425 } 426 427 @Override /* Overridden from HtmlElement */ 428 public Button onchange(String value) { 429 super.onchange(value); 430 return this; 431 } 432 433 @Override /* Overridden from HtmlElement */ 434 public Button onclick(String value) { 435 super.onclick(value); 436 return this; 437 } 438 439 @Override /* Overridden from HtmlElement */ 440 public Button oncuechange(String value) { 441 super.oncuechange(value); 442 return this; 443 } 444 445 @Override /* Overridden from HtmlElement */ 446 public Button ondblclick(String value) { 447 super.ondblclick(value); 448 return this; 449 } 450 451 @Override /* Overridden from HtmlElement */ 452 public Button ondurationchange(String value) { 453 super.ondurationchange(value); 454 return this; 455 } 456 457 @Override /* Overridden from HtmlElement */ 458 public Button onemptied(String value) { 459 super.onemptied(value); 460 return this; 461 } 462 463 @Override /* Overridden from HtmlElement */ 464 public Button onended(String value) { 465 super.onended(value); 466 return this; 467 } 468 469 @Override /* Overridden from HtmlElement */ 470 public Button onerror(String value) { 471 super.onerror(value); 472 return this; 473 } 474 475 @Override /* Overridden from HtmlElement */ 476 public Button onfocus(String value) { 477 super.onfocus(value); 478 return this; 479 } 480 481 @Override /* Overridden from HtmlElement */ 482 public Button oninput(String value) { 483 super.oninput(value); 484 return this; 485 } 486 487 @Override /* Overridden from HtmlElement */ 488 public Button oninvalid(String value) { 489 super.oninvalid(value); 490 return this; 491 } 492 493 @Override /* Overridden from HtmlElement */ 494 public Button onkeydown(String value) { 495 super.onkeydown(value); 496 return this; 497 } 498 499 @Override /* Overridden from HtmlElement */ 500 public Button onkeypress(String value) { 501 super.onkeypress(value); 502 return this; 503 } 504 505 @Override /* Overridden from HtmlElement */ 506 public Button onkeyup(String value) { 507 super.onkeyup(value); 508 return this; 509 } 510 511 @Override /* Overridden from HtmlElement */ 512 public Button onload(String value) { 513 super.onload(value); 514 return this; 515 } 516 517 @Override /* Overridden from HtmlElement */ 518 public Button onloadeddata(String value) { 519 super.onloadeddata(value); 520 return this; 521 } 522 523 @Override /* Overridden from HtmlElement */ 524 public Button onloadedmetadata(String value) { 525 super.onloadedmetadata(value); 526 return this; 527 } 528 529 @Override /* Overridden from HtmlElement */ 530 public Button onloadstart(String value) { 531 super.onloadstart(value); 532 return this; 533 } 534 535 @Override /* Overridden from HtmlElement */ 536 public Button onmousedown(String value) { 537 super.onmousedown(value); 538 return this; 539 } 540 541 @Override /* Overridden from HtmlElement */ 542 public Button onmouseenter(String value) { 543 super.onmouseenter(value); 544 return this; 545 } 546 547 @Override /* Overridden from HtmlElement */ 548 public Button onmouseleave(String value) { 549 super.onmouseleave(value); 550 return this; 551 } 552 553 @Override /* Overridden from HtmlElement */ 554 public Button onmousemove(String value) { 555 super.onmousemove(value); 556 return this; 557 } 558 559 @Override /* Overridden from HtmlElement */ 560 public Button onmouseout(String value) { 561 super.onmouseout(value); 562 return this; 563 } 564 565 @Override /* Overridden from HtmlElement */ 566 public Button onmouseover(String value) { 567 super.onmouseover(value); 568 return this; 569 } 570 571 @Override /* Overridden from HtmlElement */ 572 public Button onmouseup(String value) { 573 super.onmouseup(value); 574 return this; 575 } 576 577 @Override /* Overridden from HtmlElement */ 578 public Button onmousewheel(String value) { 579 super.onmousewheel(value); 580 return this; 581 } 582 583 @Override /* Overridden from HtmlElement */ 584 public Button onpause(String value) { 585 super.onpause(value); 586 return this; 587 } 588 589 @Override /* Overridden from HtmlElement */ 590 public Button onplay(String value) { 591 super.onplay(value); 592 return this; 593 } 594 595 @Override /* Overridden from HtmlElement */ 596 public Button onplaying(String value) { 597 super.onplaying(value); 598 return this; 599 } 600 601 @Override /* Overridden from HtmlElement */ 602 public Button onprogress(String value) { 603 super.onprogress(value); 604 return this; 605 } 606 607 @Override /* Overridden from HtmlElement */ 608 public Button onratechange(String value) { 609 super.onratechange(value); 610 return this; 611 } 612 613 @Override /* Overridden from HtmlElement */ 614 public Button onreset(String value) { 615 super.onreset(value); 616 return this; 617 } 618 619 @Override /* Overridden from HtmlElement */ 620 public Button onresize(String value) { 621 super.onresize(value); 622 return this; 623 } 624 625 @Override /* Overridden from HtmlElement */ 626 public Button onscroll(String value) { 627 super.onscroll(value); 628 return this; 629 } 630 631 @Override /* Overridden from HtmlElement */ 632 public Button onseeked(String value) { 633 super.onseeked(value); 634 return this; 635 } 636 637 @Override /* Overridden from HtmlElement */ 638 public Button onseeking(String value) { 639 super.onseeking(value); 640 return this; 641 } 642 643 @Override /* Overridden from HtmlElement */ 644 public Button onselect(String value) { 645 super.onselect(value); 646 return this; 647 } 648 649 @Override /* Overridden from HtmlElement */ 650 public Button onshow(String value) { 651 super.onshow(value); 652 return this; 653 } 654 655 @Override /* Overridden from HtmlElement */ 656 public Button onstalled(String value) { 657 super.onstalled(value); 658 return this; 659 } 660 661 @Override /* Overridden from HtmlElement */ 662 public Button onsubmit(String value) { 663 super.onsubmit(value); 664 return this; 665 } 666 667 @Override /* Overridden from HtmlElement */ 668 public Button onsuspend(String value) { 669 super.onsuspend(value); 670 return this; 671 } 672 673 @Override /* Overridden from HtmlElement */ 674 public Button ontimeupdate(String value) { 675 super.ontimeupdate(value); 676 return this; 677 } 678 679 @Override /* Overridden from HtmlElement */ 680 public Button ontoggle(String value) { 681 super.ontoggle(value); 682 return this; 683 } 684 685 @Override /* Overridden from HtmlElement */ 686 public Button onvolumechange(String value) { 687 super.onvolumechange(value); 688 return this; 689 } 690 691 @Override /* Overridden from HtmlElement */ 692 public Button onwaiting(String value) { 693 super.onwaiting(value); 694 return this; 695 } 696 697 @Override /* Overridden from HtmlElement */ 698 public Button spellcheck(Object value) { 699 super.spellcheck(value); 700 return this; 701 } 702 703 @Override /* Overridden from HtmlElement */ 704 public Button style(String value) { 705 super.style(value); 706 return this; 707 } 708 709 @Override /* Overridden from HtmlElement */ 710 public Button tabindex(Object value) { 711 super.tabindex(value); 712 return this; 713 } 714 715 @Override /* Overridden from HtmlElement */ 716 public Button title(String value) { 717 super.title(value); 718 return this; 719 } 720 721 @Override /* Overridden from HtmlElement */ 722 public Button translate(Object value) { 723 super.translate(value); 724 return this; 725 } 726 727 @Override /* Overridden from HtmlElementMixed */ 728 public Button child(Object value) { 729 super.child(value); 730 return this; 731 } 732 733 @Override /* Overridden from HtmlElementMixed */ 734 public Button children(Object...value) { 735 super.children(value); 736 return this; 737 } 738}