Wicket - 获取标记元素的主体 [英] Wicket - getting body of markup element
问题描述
假设我的标记看起来像这样:
Assuming I have markup that looks like this :
<span wicket:id="text">Some text that I'd like to read</span>
是否可以在某处获取标签正文的内容,或者是否可以通过wicket?
Is it possible to get the content of the body of the tag somewhere, or is it irremediably stripped by wicket?
编辑:
我的目的是实现某种简单的CMS。用户需要能够以 tex> a ^ 2< / tex>
的形式输入LaTeX公式,然后我将使用RenderedDynamicImageResource进行渲染。其他标签需要以类似的方式解释。我设想用 Panel
分两步完成:
Edit :
My intent is to implement some kind of simple CMS. Users need to be able to enter LaTeX formulas, in the form of tex>a^2</tex>
that I would then render with a RenderedDynamicImageResource. Other tags need to be interpreted in a similar way. I envisioned to do it in two steps with a Panel
like this :
public class LightweightMarkupPanel extends Panel implements IComponentResolver {
public LightweightMarkupPanel ( String id ) {
super( id );
}
@Override
public MarkupStream getAssociatedMarkupStream( boolean throwException ) {
// Get the lightweight markup and convert it to wicket markup
...
}
@Override
public boolean resolve( MarkupContainer container, MarkupStream markupStream, ComponentTag tag ) {
// AutoAdd components as needed
...
}
}
我一直在努力解决这个问题,也许我正在寻找错误的方向。
I've been struggling with this problem for a while, so maybe I'm searching in the wrong direction.
推荐答案
MarkupStream
Component的对象包含原始HTML主体。
您可以使用markupStream.get()。toString()方法检索它,如下所示:
The MarkupStream
object of the Component contains the raw HTML body.
You can retrieve it using the markupStream.get().toString() method like this:
// <span wicket:id="message">message will be here</span>
add(new Label("message", "If you see this message ..."){
@Override
protected void onComponentTagBody(
MarkupStream markupStream, ComponentTag openTag) {
markupStream.get(); // "message will be here"
super.onComponentTagBody(markupStream, openTag);
}
});
这篇关于Wicket - 获取标记元素的主体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!