哪个是渲染任意 HTML 的最佳 Wicket 组件?
我正在使用 Apache Wicket 实现一个简单的 Markdown wiki。 wiki 通常会根据用户输入的内容呈现任意 HTML。
我对哪个 Wicket 组件最适合呈现此类任意 HTML 感到有点困惑。
我尝试了 Label 组件,但它没有正确渲染列表,MultilineLabel 也没有(它放置中断而不是常规列表 HTML)。
感谢您的任何帮助。
更新:标签组件工作完美。我的错误是我没能让它更早地工作。这是一些糟糕的样式表和深夜编码的结合。感谢您提供有用的答案。正如建议的那样,我还将查看一些所见即所得编辑器,它们实际上可能比 Markdown 更好。 Visual Wicket 似乎特别有前途。
I am implementing a simple markdown wiki using Apache Wicket. The wiki would typically render any arbitrary HTML based on what the user has entered.
I am a bit confused about which Wicket component would be best suited to render such arbitrary HTML.
I tried the Label component but it does not render lists properly, neither does the MultilineLabel (which puts breaks instead of the regular list HTML).
Thanks for any help.
UPDATE: The Label component works perfectly. It was my mistake that I was not able to get it to work earlier. It was a combination of some bad stylesheets and late night coding. Thanks for the helpfull answers. As suggested, I am also going to check out some WYSIWYG editors, which actually might work out better than markdown. Visural Wicket seems especially promising.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您要渲染的内容不大,或者已经表示为字符串,则 Label 可以很好地工作,只需调用
label.setEscapeModelStrings(false);
以确保它按原样打印字符串。但是,如果您的 HTML 内容是动态生成的,或者从 InputStream/Reader 读取的,并且您不想将其保留在内存中,则可以直接使用 WebComponent,并重写方法
onComponentTagBody()
。这样,您可以直接写入响应,而不是填充内存缓冲区,而是将其转换为字符串,然后写入响应(如果您使用 Label,则会发生这种情况)。两种情况的示例代码:
HomePage.java
HomePage.html
If what you want to render is not big, or is already represented as a String, Label will work well, just call
label.setEscapeModelStrings(false);
to ensure it prints the string as is.But, if your HTML content is generated dynamically, or read from an InputStream/Reader, and you don't want to keep it in memory, you could use WebComponent directly, and override the method
onComponentTagBody()
. This way, you write directly to the response, instead of filling a in-memory buffer, transform it to a String, and then write to the response (which happens if you use Label).Sample code, for both cases:
HomePage.java
HomePage.html
它是
Label
,调用Component.setEscapeModelStrings(false)
不过要渲染模型返回的原始 html。It is
Label
, callComponent.setEscapeModelStrings(false)
though to render the raw html your model returns.