问题
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.
回答1:
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);
}
});
来源:https://stackoverflow.com/questions/4609871/wicket-getting-body-of-markup-element