0

Parse EL in HTML content

asked 2014-01-09 16:24:29 +0800

michaelh gravatar image michaelh
27 1

Hi,

I'm working on a project that involves a home grown CMS. We have a service class that loads content from the database and displays this in a zul file.

  <html content="@{win$composer.topic.body}"/>

From the Javadocs, it says:

"Unlike other methods, the content assigned to this method is generated directly to the browser without escaping. ..."

When I view the page it shows my EL code ${a.b.c} where "a" would be a spring bean.

Is there a way to read in from the database column, and parse the EL and evaluate the expressions where the spring bean is referenced or a variable in the pageScope, sessionScope can be reference for a value?

Thanks!

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-01-13 06:11:48 +0800

cor3000 gravatar image cor3000
4606 2 7
ZK Team

updated 2014-01-13 06:16:07 +0800

Hi,

the EL-expressions in the style of ${...} are replaced after the page has been parsed, before the attributes are set to the components (in this case before setContent(String content) is called). The resulting content, then is not altered and escaped anymore.

In your case you are using a binding annotation which is executed after the page parsing and only causes a setContent no replacement happens automatically.

There is a way to parse and include content from a CMS and apply EL expressions. using org.zkoss.zk.ui.Executions.createComponentsDirectly(String, String, Component, Map).

I put together an example on zk fiddle that reproduces your problem and compares 2 different ways to solve it (using native html elements vs xhtml namespace components). The example uses a component scoped variable "version" but the same will also work, if a variable resolver enables spring beans.

Regards,

Robert

link publish delete flag offensive edit
Your answer
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
1 follower

RSS

Stats

Asked: 2014-01-09 16:24:29 +0800

Seen: 15 times

Last updated: Jan 13 '14

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