Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Java API for configuring white-space styles #4577

Closed
Legioth opened this issue Sep 3, 2018 · 0 comments · Fixed by #11919
Closed

Add a Java API for configuring white-space styles #4577

Legioth opened this issue Sep 3, 2018 · 0 comments · Fixed by #11919
Assignees

Comments

@Legioth
Copy link
Member

Legioth commented Sep 3, 2018

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:

  1. 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.
  2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants