tags:

views:

355

answers:

3

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.

+1  A: 

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
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
A: 

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
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
Yup, you are right, my bad.
Jawher
+1  A: 

You can read more about this here and here

Karussell