2011-01-05 56 views
1

的身體假設我有標記,看起來像這樣:檢票 - 讓標記元素

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

是否有可能獲得標籤的正文內容的地方,或者是無可挽回檢票剝離?

編輯: 我的意圖是實施某種簡單的CMS。用戶需要能夠以tex>a^2</tex>的形式輸入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 
     ... 
    } 
} 

我一直在這個問題一會兒掙扎,所以也許我在尋找在錯誤的方向。

+0

獲取內容在哪裏?你想讓「我想閱讀的一些文字」留下來嗎? – jzd 2011-01-05 23:59:08

回答

4

組件的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); 
    } 
});