我正在尝试显示带有换行符的GWT UiField HTML对象,但是它似乎不起作用。
我接受一个字符串,使用SimpleHtmlSanitizer
对其进行清理,然后换行符在AlertWidget(它是一个DialogBox
)中显示为文本而不是html。
@UiField
HTML description;
public AlertWidget(String htmlMessage) {
SafeHtml safeMessage = SimpleHtmlSanitizer.sanitizeHtml(htmlMessage);
setWidget(uiBinder.createAndBindUi(this));
this.description.setHTML(safeMessage);
}
在页面上,对话框的内容最终看起来与输入的String完全相同:
The first error<br>the second error
在我的想法中,我可以看到经过清理的SafeHtml包含
safe
值:The first error<br>the second error
最佳答案
查看sanitizeHtml的文档。顶部是受支持标签的列表。不支持折线标签。
我会尝试其他用于创建SafeHTML的机制:
http://www.gwtproject.org/javadoc/latest/com/google/gwt/safehtml/shared/SafeHtmlBuilder.html