Wicket - 获取标记元素的主体

发布于 2024-10-10 09:38:06 字数 933 浏览 2 评论 0原文

假设我有如下所示的标记:

<span wicket:id="text">Some text that I'd like to read</span>

是否可以在某处获取标签正文的内容,或者它是否被检票口不可挽回地剥离?

编辑: 我的目的是实现某种简单的 CMS。用户需要能够以 tex>a^2 的形式输入 LaTeX 公式,然后我将使用 RenderedDynamicImageResource 进行渲染。其他标签需要以类似的方式解释。我设想用这样的 Panel 分两步完成:

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
        ...
    }
}

我已经在这个问题上苦苦挣扎了一段时间,所以也许我正在寻找错误的方向。

Assuming I have markup that looks like this :

<span wicket:id="text">Some text that I'd like to read</span>

Is it possible to get the content of the body of the tag somewhere, or is it irremediably stripped by wicket?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

永言不败 2024-10-17 09:38:06

组件的 MarkupStream 对象包含原始 HTML 主体。
您可以使用 markupStream.get().toString() 方法检索它,如下所示:

// <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);
     }
});

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);
     }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文