如何在 Wicket 元素中显示 html 文本? [英] How to display html text within a Wicket element?

查看:51
本文介绍了如何在 Wicket 元素中显示 html 文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 wicket 元素中动态显示 html,即富文本.一个例子就像在 div 标签中显示富文本电子邮件.我怎样才能用 wicket 完成这项工作.wicket Label 组件似乎不支持这一点.有没有组件可以

解决方案

在优秀的 Manning Wicket in Action 中找到了这个:

add(new Label("markup", "

Hello!

").setEscapeModelStrings(false));

<块引用>

对 setEscapeModelStrings 的调用告诉 Wicket 不要转义提供的字符串的内容,并将内容呈现到结果标记中.这可以解决问题,正如您在图 5.4 的右侧屏幕截图中看到的那样.请注意,此设置适用于所有 Wicket 组件,但主要用于标签.

然而,正如书中还指出的,您应该注意脚本注入攻击..

i'm trying to display html i.e. rich text within a wicket element dynamically. An example is like displaying a rich text email within a div tag. how can i get this done with wicket. the wicket Label component doesn't seem to support this. is there a component that does

解决方案

Found this in the excellent Manning Wicket in Action:

add(new Label("markup", "<h1>Hello!</h1>").setEscapeModelStrings(false));

The call to setEscapeModelStrings tells Wicket not to escape the contents of the provided string, and to render the contents into the resulting markup. This does the trick, as you can see in the right screenshot in figure 5.4. Note that this setting is available on all Wicket components, but it’s primarily useful on labels.

As the book also notes however, you should be aware of script-injection attacks..

这篇关于如何在 Wicket 元素中显示 html 文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆