You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When showing text inside any component or element, it's sometimes desirable to make it honor line breaks and other whitespace from the original String, so that e.g. button.setText("Hello\nworld"); would be rendered on two lines.
There are currently two bad ways of achieving this:
Show the contents as HTML, e.g button.add(new HTML("Hello<br>world"));. The big drawback of this practice is that it opens up the application for XSS attacks for any text that may originate from users.
Use the Element API to set a suitable white-space style for the component, e.g. button.getElement().getStyle().set("white-space", "pre-line");. This approach requires that you are aware of this CSS feature and that you know which setting to actually use (the spec defines 5 different potential values).
I propose that HasText is enhanced with a typesafe API for configuring the white-space style based on an enum. With this, the example would be button.setWhiteSpace(WhiteSpace.PRE_LINE);. We could also consider an overload of the setText method that also sets a white space mode: button.setText("Hello\nWorld", WhiteSpace.PRE_LINE);, and then maybe also supplement various String constructors that delegate to setText.
The text was updated successfully, but these errors were encountered:
When showing text inside any component or element, it's sometimes desirable to make it honor line breaks and other whitespace from the original String, so that e.g.
button.setText("Hello\nworld");
would be rendered on two lines.There are currently two bad ways of achieving this:
button.add(new HTML("Hello<br>world"));
. The big drawback of this practice is that it opens up the application for XSS attacks for any text that may originate from users.white-space
style for the component, e.g.button.getElement().getStyle().set("white-space", "pre-line");
. This approach requires that you are aware of this CSS feature and that you know which setting to actually use (the spec defines 5 different potential values).I propose that
HasText
is enhanced with a typesafe API for configuring thewhite-space
style based on an enum. With this, the example would bebutton.setWhiteSpace(WhiteSpace.PRE_LINE);
. We could also consider an overload of thesetText
method that also sets a white space mode:button.setText("Hello\nWorld", WhiteSpace.PRE_LINE);
, and then maybe also supplement various String constructors that delegate tosetText
.The text was updated successfully, but these errors were encountered: