You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

components-richtextarea.asciidoc 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ---
  2. title: RichTextArea
  3. order: 12
  4. layout: page
  5. ---
  6. [[components.richtextarea]]
  7. = RichTextArea
  8. ifdef::web[]
  9. [.sampler]
  10. image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/data-input/text-input/rich-text-area"]
  11. endif::web[]
  12. The [classname]#RichTextArea# field allows entering or editing formatted text.
  13. The toolbar provides all basic editing functionalities. The text content of
  14. [classname]#RichTextArea# is represented in HTML format.
  15. [classname]#RichTextArea# inherits [classname]#TextField# and does not add any
  16. API functionality over it. You can add new functionality by extending the
  17. client-side components [classname]#VRichTextArea# and
  18. [classname]#VRichTextToolbar#.
  19. As with [classname]#TextField#, the textual content of the rich text area is the
  20. [classname]#Property# of the field and can be set with [methodname]#setValue()#
  21. and read with [methodname]#getValue()#.
  22. [source, java]
  23. ----
  24. // Create a rich text area
  25. final RichTextArea rtarea = new RichTextArea();
  26. rtarea.setCaption("My Rich Text Area");
  27. // Set initial content as HTML
  28. rtarea.setValue("<h1>Hello</h1>\n" +
  29. "<p>This rich text area contains some text.</p>");
  30. ----
  31. .Rich Text Area Component
  32. image::img/richtextarea-example1.png[width=60%, scaledwidth=90%]
  33. Above, we used context-specific tags such as [literal]#++<h1>++# in the initial
  34. HTML content. The rich text area component does not allow creating such tags,
  35. only formatting tags, but it does preserve them unless the user edits them away.
  36. Any non-visible whitespace such as the new line character ( [literal]#++\n++#)
  37. are removed from the content. For example, the value set above will be as
  38. follows when read from the field with [methodname]#getValue()#:
  39. [source, html]
  40. ----
  41. <h1>Hello</h1> <p>This rich text area contains some text.</p>
  42. ----
  43. [WARNING]
  44. .Cross-Site Scripting Warning
  45. ====
  46. The user input from a [classname]#RichTextArea# is transmitted as HTML from the
  47. browser to server-side and is not sanitized. As the entire purpose of the
  48. [classname]#RichTextArea# component is to allow input of formatted text, you can
  49. not sanitize it just by removing all HTML tags. Also many attributes, such as
  50. [parameter]#style#, should pass through the sanitization.
  51. See
  52. <<dummy/../../../framework/advanced/advanced-security#advanced.security.sanitizing,"Sanitizing
  53. User Input to Prevent Cross-Site Scripting">> for more details on Cross-Site
  54. scripting vulnerabilities and sanitization of user input.
  55. ====
  56. [[components.richtextarea.localization]]
  57. == Localizing RichTextArea Toolbars
  58. The rich text area is one of the few components in Vaadin that contain textual
  59. labels. The selection boxes in the toolbar are in English and currently can not
  60. be localized in any other way than by inheriting or reimplementing the
  61. client-side [classname]#VRichTextToolbar# widget. The buttons can be localized
  62. simply with CSS by downloading a copy of the toolbar background image, editing
  63. it, and replacing the default toolbar. The toolbar is a single image file from
  64. which the individual button icons are picked, so the order of the icons is
  65. different from the rendered. The image file depends on the client-side
  66. implementation of the toolbar.
  67. == CSS Style Rules
  68. [source, css]
  69. ----
  70. .v-richtextarea { }
  71. .v-richtextarea .gwt-RichTextToolbar { }
  72. .v-richtextarea .gwt-RichTextArea { }
  73. ----
  74. The rich text area consists of two main parts: the toolbar with overall style
  75. [literal]#++.gwt-RichTextToolbar++# and the editor area with style
  76. [literal]#++.gwt-RichTextArea++#. The editor area obviously contains all the
  77. elements and their styles that the HTML content contains. The toolbar contains
  78. buttons and drop-down list boxes with the following respective style names:
  79. [source, css]
  80. ----
  81. .gwt-ToggleButton { }
  82. .gwt-ListBox { }
  83. ----