0

Html templating by ZK

asked 2010-11-12 10:19:04 +0800

xmedeko gravatar image xmedeko
1031 1 16
http://xmedeko.blogspot.c...

Hi,
I have

<html id="html" />

I am generating a content as a string in my application.

StringBuilder sb = new StringBuilder();
sb.append(<ul><li>).append...
html.setContent(sb.toString());

Is there any way, how to use DSP or JSP as templates to build a content of html tag, so as EL expressions may be used? I mean a template l like

<li>${arg.name} has ${arg.count} items</li> 

and use it in the code:
for (...) {
  sb.append(load("template.jsp, arg));
}

I know I can use some templates, like FreeMaker with ZK. But I need this just for one page so I do not want to employ a special technology for that.

Thanks
Andy

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2010-11-12 14:18:54 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

If you set variable names in doBeforeCompose(...) you can use those in EL.

link publish delete flag offensive edit

answered 2010-11-13 06:35:47 +0800

xmedeko gravatar image xmedeko
1031 1 16
http://xmedeko.blogspot.c...

Cary: I would like to use some simple HTML template, without any ZK controller. I.e. I have to make a list

<ul>
<li>...<li>
<li>...<li>
</ul>

I would like to have some template for the <li>....</li>, which would resolve EL variables. I would like to reuse this template with different values. I do not want to use EL "forEach", since I would like to plug the templates together sometimes.

This problem is not a much ZK related. I just the whole app written in ZK, so I would be happy, if I could use ZK for this problem, too.

link publish delete flag offensive edit

answered 2010-11-15 04:49:06 +0800

xmedeko gravatar image xmedeko
1031 1 16
http://xmedeko.blogspot.c...

Got it:

ExpressionEvaluatorImpl evaluator = new ExpressionEvaluatorImpl(true);
Map map = new HashMap();
map.put("cosi", 2);
map.put("cosi2", 4);
SimpleResolver sr = new SimpleResolver(map);
Object value = evaluator.evaluate("Hello ${cosi} and maybe ${cosi2}.", String.class, sr, null); 

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-11-12 10:19:04 +0800

Seen: 280 times

Last updated: Nov 15 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More