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 org.apache.juneau.annotation.*; 020 021/** 022 * DTO for an HTML <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#the-textarea-element"><textarea></a> 023 * element. 024 * 025 * <p> 026 * The textarea element represents a multiline text input control. It allows users to enter and edit 027 * text over multiple lines, making it suitable for longer text content such as comments, descriptions, 028 * or messages. The textarea element supports various attributes for controlling its size, behavior, 029 * and validation. 030 * 031 * <h5 class='section'>Examples:</h5> 032 * <p class='bcode w800'> 033 * <jk>import static</jk> org.apache.juneau.bean.html5.HtmlBuilder.*; 034 * 035 * <jc>// Basic textarea</jc> 036 * Textarea <jv>basic</jv> = <jsm>textarea</jsm>(<js>"comments"</js>) 037 * .rows(4) 038 * .cols(50); 039 * 040 * <jc>// Textarea with placeholder and validation</jc> 041 * Textarea <jv>validated</jv> = <jsm>textarea</jsm>(<js>"description"</js>) 042 * .placeholder(<js>"Enter a description..."</js>) 043 * .required(<jk>true</jk>) 044 * .minlength(10) 045 * .maxlength(500); 046 * 047 * <jc>// Textarea with initial content</jc> 048 * Textarea <jv>withContent</jv> = <jsm>textarea</jsm>(<js>"message"</js>) 049 * .text(<js>"Default message text"</js>); 050 * 051 * <jc>// Textarea with styling and behavior</jc> 052 * Textarea <jv>styled</jv> = <jsm>textarea</jsm>(<js>"feedback"</js>) 053 * ._class(<js>"large-textarea"</js>) 054 * .rows(6) 055 * .cols(60) 056 * .placeholder(<js>"Please provide your feedback..."</js>) 057 * .wrap(<js>"hard"</js>); 058 * 059 * <jc>// Disabled textarea</jc> 060 * Textarea <jv>disabled</jv> = <jsm>textarea</jsm>(<js>"readonly"</js>) 061 * .disabled(true) 062 * .text("This textarea is disabled"); 063 * 064 * // Textarea with form association 065 * Textarea external = new Textarea() 066 * .name="external" 067 * .form="myForm" 068 * .placeholder="This textarea is outside the form"; 069 * </p> 070 * 071 * <p> 072 * The following convenience methods are provided for constructing instances of this bean: 073 * <ul class='javatree'> 074 * <li class='jc'>{@link HtmlBuilder} 075 * <ul class='javatree'> 076 * <li class='jm'>{@link HtmlBuilder#textarea() textarea()} 077 * <li class='jm'>{@link HtmlBuilder#textarea(String, String) textarea(String, String)} 078 * </ul> 079 * </ul> 080 * </p> 081 * 082 * <h5 class='section'>See Also:</h5><ul> 083 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a> 084 * </ul> 085 */ 086@Bean(typeName = "textarea") 087public class Textarea extends HtmlElementRawText { 088 089 /** 090 * Creates an empty {@link Textarea} element. 091 */ 092 public Textarea() {} 093 094 /** 095 * Creates a {@link Textarea} element with the specified {@link Textarea#name(String)} attribute and 096 * {@link Textarea#text(Object)} node. 097 * 098 * @param name The {@link Textarea#name(String)} attribute. 099 * @param text The {@link Textarea#text(Object)} node. 100 */ 101 public Textarea(String name, String text) { 102 name(name).text(text); 103 } 104 105 @Override /* Overridden from HtmlElement */ 106 public Textarea _class(String value) { // NOSONAR - Intentional naming. 107 super._class(value); 108 return this; 109 } 110 111 @Override /* Overridden from HtmlElement */ 112 public Textarea accesskey(String value) { 113 super.accesskey(value); 114 return this; 115 } 116 117 @Override /* Overridden from HtmlElement */ 118 public Textarea attr(String key, Object val) { 119 super.attr(key, val); 120 return this; 121 } 122 123 @Override /* Overridden from HtmlElement */ 124 public Textarea attrUri(String key, Object val) { 125 super.attrUri(key, val); 126 return this; 127 } 128 129 /** 130 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fe-autocomplete">autocomplete</a> attribute. 131 * 132 * <p> 133 * Specifies whether the browser should automatically complete the form field based on user's previous input. 134 * 135 * <p> 136 * Possible values: 137 * <ul> 138 * <li><js>"on"</js> - Allow autocomplete (default)</li> 139 * <li><js>"off"</js> - Disable autocomplete</li> 140 * <li><js>"name"</js> - Autocomplete for name fields</li> 141 * <li><js>"email"</js> - Autocomplete for email fields</li> 142 * <li><js>"username"</js> - Autocomplete for username fields</li> 143 * <li><js>"current-password"</js> - Autocomplete for current password</li> 144 * <li><js>"new-password"</js> - Autocomplete for new password</li> 145 * </ul> 146 * 147 * @param value Autocomplete behavior for the form field. 148 * @return This object. 149 */ 150 public Textarea autocomplete(String value) { 151 attr("autocomplete", value); 152 return this; 153 } 154 155 /** 156 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fe-autofocus">autofocus</a> attribute. 157 * 158 * <p> 159 * Automatically focus the form control when the page is loaded. 160 * 161 * @param value 162 * The new value for this attribute. 163 * Typically a {@link Boolean} or {@link String}. 164 * @return This object. 165 */ 166 public Textarea autofocus(Object value) { 167 attr("autofocus", value); 168 return this; 169 } 170 171 /** 172 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-textarea-cols">cols</a> attribute. 173 * 174 * <p> 175 * Specifies the visible width of the textarea in characters. This is a hint for the browser 176 * and may not be exactly followed depending on the font and styling. 177 * 178 * @param value The visible width of the textarea in characters. 179 * @return This object. 180 */ 181 public Textarea cols(Object value) { 182 attr("cols", value); 183 return this; 184 } 185 186 @Override /* Overridden from HtmlElement */ 187 public Textarea contenteditable(Object value) { 188 super.contenteditable(value); 189 return this; 190 } 191 192 @Override /* Overridden from HtmlElement */ 193 public Textarea dir(String value) { 194 super.dir(value); 195 return this; 196 } 197 198 /** 199 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fe-dirname">dirname</a> attribute. 200 * 201 * <p> 202 * Specifies the name of a hidden form field that will be submitted along with the textarea value, 203 * containing the text direction (ltr or rtl) of the textarea content. 204 * 205 * <p> 206 * This is useful for forms that need to preserve text direction information when submitted. 207 * The hidden field will contain either "ltr" or "rtl" based on the textarea's direction. 208 * 209 * @param value The name of the hidden field for directionality information. 210 * @return This object. 211 */ 212 public Textarea dirname(String value) { 213 attr("dirname", value); 214 return this; 215 } 216 217 /** 218 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fe-disabled">disabled</a> attribute. 219 * 220 * <p> 221 * Whether the form control is disabled. 222 * 223 * <p> 224 * This attribute uses deminimized values: 225 * <ul> 226 * <li><jk>false</jk> - Attribute is not added</li> 227 * <li><jk>true</jk> - Attribute is added as <js>"disabled"</js></li> 228 * <li>Other values - Passed through as-is</li> 229 * </ul> 230 * 231 * @param value 232 * The new value for this attribute. 233 * Typically a {@link Boolean} or {@link String}. 234 * @return This object. 235 */ 236 public Textarea disabled(Object value) { 237 attr("disabled", deminimize(value, "disabled")); 238 return this; 239 } 240 241 /** 242 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fae-form">form</a> attribute. 243 * 244 * <p> 245 * Associates the textarea with a form element by specifying the form's ID. This allows the textarea 246 * to be placed outside the form element while still being part of the form submission. 247 * 248 * <p> 249 * The value should match the ID of a form element in the same document. 250 * 251 * @param value The ID of the form element to associate with this textarea. 252 * @return This object. 253 */ 254 public Textarea form(String value) { 255 attr("form", value); 256 return this; 257 } 258 259 @Override /* Overridden from HtmlElement */ 260 public Textarea hidden(Object value) { 261 super.hidden(value); 262 return this; 263 } 264 265 @Override /* Overridden from HtmlElement */ 266 public Textarea id(String value) { 267 super.id(value); 268 return this; 269 } 270 271 /** 272 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#inputmode">inputmode</a> attribute. 273 * 274 * <p> 275 * Provides a hint to browsers about the type of virtual keyboard to display on mobile devices. 276 * 277 * <p> 278 * Possible values: 279 * <ul> 280 * <li><js>"none"</js> - No virtual keyboard</li> 281 * <li><js>"text"</js> - Standard text keyboard (default)</li> 282 * <li><js>"tel"</js> - Telephone number keyboard</li> 283 * <li><js>"url"</js> - URL keyboard with .com key</li> 284 * <li><js>"email"</js> - Email keyboard with @ key</li> 285 * <li><js>"numeric"</js> - Numeric keyboard</li> 286 * <li><js>"decimal"</js> - Decimal number keyboard</li> 287 * <li><js>"search"</js> - Search keyboard</li> 288 * </ul> 289 * 290 * @param value The type of virtual keyboard to display. 291 * @return This object. 292 */ 293 public Textarea inputmode(String value) { 294 attr("inputmode", value); 295 return this; 296 } 297 298 @Override /* Overridden from HtmlElement */ 299 public Textarea lang(String value) { 300 super.lang(value); 301 return this; 302 } 303 304 /** 305 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-textarea-maxlength">maxlength</a> attribute. 306 * 307 * <p> 308 * Maximum length of value. 309 * 310 * @param value 311 * The new value for this attribute. 312 * Typically a {@link Number} or {@link String}. 313 * @return This object. 314 */ 315 public Textarea maxlength(Object value) { 316 attr("maxlength", value); 317 return this; 318 } 319 320 /** 321 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-textarea-minlength">minlength</a> attribute. 322 * 323 * <p> 324 * Minimum length of value. 325 * 326 * @param value 327 * The new value for this attribute. 328 * Typically a {@link Number} or {@link String}. 329 * @return This object. 330 */ 331 public Textarea minlength(Object value) { 332 attr("minlength", value); 333 return this; 334 } 335 336 /** 337 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-fe-name">name</a> attribute. 338 * 339 * <p> 340 * Specifies the name of the form control. This name is used when the form is submitted and 341 * can be used to access the element via the form.elements API. 342 * 343 * <p> 344 * The name should be unique within the form and should not contain spaces or special characters. 345 * 346 * @param value The name of the form control for submission and API access. 347 * @return This object. 348 */ 349 public Textarea name(String value) { 350 attr("name", value); 351 return this; 352 } 353 354 @Override /* Overridden from HtmlElement */ 355 public Textarea onabort(String value) { 356 super.onabort(value); 357 return this; 358 } 359 360 @Override /* Overridden from HtmlElement */ 361 public Textarea onblur(String value) { 362 super.onblur(value); 363 return this; 364 } 365 366 @Override /* Overridden from HtmlElement */ 367 public Textarea oncancel(String value) { 368 super.oncancel(value); 369 return this; 370 } 371 372 @Override /* Overridden from HtmlElement */ 373 public Textarea oncanplay(String value) { 374 super.oncanplay(value); 375 return this; 376 } 377 378 @Override /* Overridden from HtmlElement */ 379 public Textarea oncanplaythrough(String value) { 380 super.oncanplaythrough(value); 381 return this; 382 } 383 384 @Override /* Overridden from HtmlElement */ 385 public Textarea onchange(String value) { 386 super.onchange(value); 387 return this; 388 } 389 390 @Override /* Overridden from HtmlElement */ 391 public Textarea onclick(String value) { 392 super.onclick(value); 393 return this; 394 } 395 396 @Override /* Overridden from HtmlElement */ 397 public Textarea oncuechange(String value) { 398 super.oncuechange(value); 399 return this; 400 } 401 402 @Override /* Overridden from HtmlElement */ 403 public Textarea ondblclick(String value) { 404 super.ondblclick(value); 405 return this; 406 } 407 408 @Override /* Overridden from HtmlElement */ 409 public Textarea ondurationchange(String value) { 410 super.ondurationchange(value); 411 return this; 412 } 413 414 @Override /* Overridden from HtmlElement */ 415 public Textarea onemptied(String value) { 416 super.onemptied(value); 417 return this; 418 } 419 420 @Override /* Overridden from HtmlElement */ 421 public Textarea onended(String value) { 422 super.onended(value); 423 return this; 424 } 425 426 @Override /* Overridden from HtmlElement */ 427 public Textarea onerror(String value) { 428 super.onerror(value); 429 return this; 430 } 431 432 @Override /* Overridden from HtmlElement */ 433 public Textarea onfocus(String value) { 434 super.onfocus(value); 435 return this; 436 } 437 438 @Override /* Overridden from HtmlElement */ 439 public Textarea oninput(String value) { 440 super.oninput(value); 441 return this; 442 } 443 444 @Override /* Overridden from HtmlElement */ 445 public Textarea oninvalid(String value) { 446 super.oninvalid(value); 447 return this; 448 } 449 450 @Override /* Overridden from HtmlElement */ 451 public Textarea onkeydown(String value) { 452 super.onkeydown(value); 453 return this; 454 } 455 456 @Override /* Overridden from HtmlElement */ 457 public Textarea onkeypress(String value) { 458 super.onkeypress(value); 459 return this; 460 } 461 462 @Override /* Overridden from HtmlElement */ 463 public Textarea onkeyup(String value) { 464 super.onkeyup(value); 465 return this; 466 } 467 468 @Override /* Overridden from HtmlElement */ 469 public Textarea onload(String value) { 470 super.onload(value); 471 return this; 472 } 473 474 @Override /* Overridden from HtmlElement */ 475 public Textarea onloadeddata(String value) { 476 super.onloadeddata(value); 477 return this; 478 } 479 480 @Override /* Overridden from HtmlElement */ 481 public Textarea onloadedmetadata(String value) { 482 super.onloadedmetadata(value); 483 return this; 484 } 485 486 @Override /* Overridden from HtmlElement */ 487 public Textarea onloadstart(String value) { 488 super.onloadstart(value); 489 return this; 490 } 491 492 @Override /* Overridden from HtmlElement */ 493 public Textarea onmousedown(String value) { 494 super.onmousedown(value); 495 return this; 496 } 497 498 @Override /* Overridden from HtmlElement */ 499 public Textarea onmouseenter(String value) { 500 super.onmouseenter(value); 501 return this; 502 } 503 504 @Override /* Overridden from HtmlElement */ 505 public Textarea onmouseleave(String value) { 506 super.onmouseleave(value); 507 return this; 508 } 509 510 @Override /* Overridden from HtmlElement */ 511 public Textarea onmousemove(String value) { 512 super.onmousemove(value); 513 return this; 514 } 515 516 @Override /* Overridden from HtmlElement */ 517 public Textarea onmouseout(String value) { 518 super.onmouseout(value); 519 return this; 520 } 521 522 @Override /* Overridden from HtmlElement */ 523 public Textarea onmouseover(String value) { 524 super.onmouseover(value); 525 return this; 526 } 527 528 @Override /* Overridden from HtmlElement */ 529 public Textarea onmouseup(String value) { 530 super.onmouseup(value); 531 return this; 532 } 533 534 @Override /* Overridden from HtmlElement */ 535 public Textarea onmousewheel(String value) { 536 super.onmousewheel(value); 537 return this; 538 } 539 540 @Override /* Overridden from HtmlElement */ 541 public Textarea onpause(String value) { 542 super.onpause(value); 543 return this; 544 } 545 546 @Override /* Overridden from HtmlElement */ 547 public Textarea onplay(String value) { 548 super.onplay(value); 549 return this; 550 } 551 552 @Override /* Overridden from HtmlElement */ 553 public Textarea onplaying(String value) { 554 super.onplaying(value); 555 return this; 556 } 557 558 @Override /* Overridden from HtmlElement */ 559 public Textarea onprogress(String value) { 560 super.onprogress(value); 561 return this; 562 } 563 564 @Override /* Overridden from HtmlElement */ 565 public Textarea onratechange(String value) { 566 super.onratechange(value); 567 return this; 568 } 569 570 @Override /* Overridden from HtmlElement */ 571 public Textarea onreset(String value) { 572 super.onreset(value); 573 return this; 574 } 575 576 @Override /* Overridden from HtmlElement */ 577 public Textarea onresize(String value) { 578 super.onresize(value); 579 return this; 580 } 581 582 @Override /* Overridden from HtmlElement */ 583 public Textarea onscroll(String value) { 584 super.onscroll(value); 585 return this; 586 } 587 588 @Override /* Overridden from HtmlElement */ 589 public Textarea onseeked(String value) { 590 super.onseeked(value); 591 return this; 592 } 593 594 @Override /* Overridden from HtmlElement */ 595 public Textarea onseeking(String value) { 596 super.onseeking(value); 597 return this; 598 } 599 600 @Override /* Overridden from HtmlElement */ 601 public Textarea onselect(String value) { 602 super.onselect(value); 603 return this; 604 } 605 606 @Override /* Overridden from HtmlElement */ 607 public Textarea onshow(String value) { 608 super.onshow(value); 609 return this; 610 } 611 612 @Override /* Overridden from HtmlElement */ 613 public Textarea onstalled(String value) { 614 super.onstalled(value); 615 return this; 616 } 617 618 @Override /* Overridden from HtmlElement */ 619 public Textarea onsubmit(String value) { 620 super.onsubmit(value); 621 return this; 622 } 623 624 @Override /* Overridden from HtmlElement */ 625 public Textarea onsuspend(String value) { 626 super.onsuspend(value); 627 return this; 628 } 629 630 @Override /* Overridden from HtmlElement */ 631 public Textarea ontimeupdate(String value) { 632 super.ontimeupdate(value); 633 return this; 634 } 635 636 @Override /* Overridden from HtmlElement */ 637 public Textarea ontoggle(String value) { 638 super.ontoggle(value); 639 return this; 640 } 641 642 @Override /* Overridden from HtmlElement */ 643 public Textarea onvolumechange(String value) { 644 super.onvolumechange(value); 645 return this; 646 } 647 648 @Override /* Overridden from HtmlElement */ 649 public Textarea onwaiting(String value) { 650 super.onwaiting(value); 651 return this; 652 } 653 654 /** 655 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-textarea-placeholder">placeholder</a> 656 * attribute. 657 * 658 * <p> 659 * Provides a hint to the user about what to enter in the textarea. The placeholder text is displayed 660 * when the textarea is empty and disappears when the user starts typing. 661 * 662 * <p> 663 * The placeholder should be a brief, helpful description of the expected input. 664 * 665 * @param value The placeholder text to display when the textarea is empty. 666 * @return This object. 667 */ 668 public Textarea placeholder(String value) { 669 attr("placeholder", value); 670 return this; 671 } 672 673 /** 674 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-textarea-readonly">readonly</a> attribute. 675 * 676 * <p> 677 * Whether to allow the value to be edited by the user. 678 * 679 * @param value 680 * The new value for this attribute. 681 * Typically a {@link Boolean} or {@link String}. 682 * @return This object. 683 */ 684 public Textarea readonly(Object value) { 685 attr("readonly", value); 686 return this; 687 } 688 689 /** 690 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-textarea-required">required</a> attribute. 691 * 692 * <p> 693 * Whether the control is required for form submission. 694 * 695 * @param value 696 * The new value for this attribute. 697 * Typically a {@link Boolean} or {@link String}. 698 * @return This object. 699 */ 700 public Textarea required(Object value) { 701 attr("required", value); 702 return this; 703 } 704 705 /** 706 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-textarea-rows">rows</a> attribute. 707 * 708 * <p> 709 * Specifies the visible height of the textarea in lines. This is a hint for the browser 710 * and may not be exactly followed depending on the font and styling. 711 * 712 * @param value The visible height of the textarea in lines. 713 * @return This object. 714 */ 715 public Textarea rows(Number value) { 716 attr("rows", value); 717 return this; 718 } 719 720 @Override /* Overridden from HtmlElement */ 721 public Textarea spellcheck(Object value) { 722 super.spellcheck(value); 723 return this; 724 } 725 726 @Override /* Overridden from HtmlElement */ 727 public Textarea style(String value) { 728 super.style(value); 729 return this; 730 } 731 732 @Override /* Overridden from HtmlElement */ 733 public Textarea tabindex(Object value) { 734 super.tabindex(value); 735 return this; 736 } 737 738 @Override /* Overridden from HtmlElementRawText */ 739 public Textarea text(Object value) { 740 super.text(value); 741 return this; 742 } 743 744 @Override /* Overridden from HtmlElement */ 745 public Textarea title(String value) { 746 super.title(value); 747 return this; 748 } 749 750 @Override /* Overridden from HtmlElement */ 751 public Textarea translate(Object value) { 752 super.translate(value); 753 return this; 754 } 755 756 /** 757 * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-textarea-wrap">wrap</a> attribute. 758 * 759 * <p> 760 * Specifies how the text in the textarea should be wrapped when the form is submitted. 761 * 762 * <p> 763 * Possible values: 764 * <ul> 765 * <li><js>"soft"</js> - Text is wrapped in the display but not in the submitted value (default)</li> 766 * <li><js>"hard"</js> - Text is wrapped in both display and submitted value</li> 767 * <li><js>"off"</js> - Text is not wrapped</li> 768 * </ul> 769 * 770 * @param value How the text should be wrapped for form submission. 771 * @return This object. 772 */ 773 public Textarea wrap(String value) { 774 attr("wrap", value); 775 return this; 776 } 777}