14

Is it possible to generate the markup for a MarkupContainer dynamically, i.e. without storing an HTML file for it?

I thought about reading the markup as a plain string from the database to offer CMS-like functionality.

Wolfgang
  • 2,367
  • 23
  • 29

2 Answers2

9

Interesting question and I'm not sure if it is possible, but my guess would be to start off looking at the IMarkupLoader and IMarkupResourceStreamProvider interfaces and implementing classes and see how far you get from there.
I'd be interested in anything you find / implement that actually gets this done!

Tim
  • 19,793
  • 8
  • 70
  • 95
  • 4
    Thanks for the hint. That did it! The MarkupContainer has to implement `IMarkupResourceStreamProvider` and its method `getMarkupResourceStream()`. Also, you create a class that derives (for example) from `AbstractResourceStream`. There, you can implement a method that just returns an `InputStream`. `getMarkupResourceStream()` then just returns an instance of this new class. The javadoc says this was even transparent to caching. – Wolfgang Jan 18 '10 at 15:38
  • 1
    This is well documented in the reference guide under [17.5 Generating HTML markup from code](http://wicket.apache.org/guide/guide/advanced.html#advanced_5). – aioobe Jan 17 '15 at 22:32
-1

Another (simpler) way to do it would be to use a label with disabled markup escaping :

Label<String> label = new Label<String>("id", "<a href='....'><span>foo<em>bar</em></span></a>");
label.setEscapeModelStrings(false);
add(label);

Be careful though, as this might lead to security breaches (HTML/JS injection).

Jawher
  • 6,937
  • 1
  • 17
  • 12
  • Thanks for your idea. I'm not sure if it's what I was looking for, though. I want to use the dynamic markup to be used by a MarkupContainer, i.e. I expect certain wicket:ids in the markup and I want to add further components to the container which should then be mapped to those ids. I'm afraid that's not possible with your solution. – Wolfgang Jan 23 '10 at 11:44
  • This is a really bad idea, considering the security breaches, but also the abuse of a Label to display plain HTML. – Rob Audenaerde Jun 17 '13 at 13:04