0

Parsing of CSS files for image URLs?

asked 2010-05-13 07:59:03 +0800

raevel2 gravatar image raevel2
72 1 2

My CSS files has background images, so I need to specify the corresponding URLs, which may vary depending on the path to the app.

I saw some example code that was using background-image:url(${c:encodeUrl("foo")};, but it seems that ZK doesn't parse my CSS files by default when I use the ZUL style element.

How can I get ZK to parse my CSS files?

How should i retrieve the URLs? is encodeURL the way to go?

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2010-05-13 21:45:04 +0800

PeterKuo gravatar image PeterKuo
481 2

@raevel2, welcome to zk.

You pointed out a non document well trick to include css file.

I would modify also.
http://docs.zkoss.org/wiki/Developer%27s_Guide#Style_Customization

You can use encodeURL() in zul, or in DSP.
I placed 1.jpg under WebContent and tried following files.
It works in both ways.

Embed css file in a dsp file, is the way how ZK preprocess css file to support encodeURL()
You may unjar zk package and refer to "box.css.dsp"

The syntax to use taglib is a little different in ZUL and dsp.
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?> --- in zul
<%@ taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" %> --- in dsp

forum_12404.zul:
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<zk>
<style>
.target1{
background-image:url(${c:encodeURL('/1.jpg')});
}
</style>
<style src="/forum_12404.css.dsp">
</style>
<div sclass="target1" height="100px" width="100px">
</div>
<div sclass="target2" height="100px" width="100px">
</div>
</zk>

forum_12404.css.dsp:
<%@ taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" %>

.target2{
background-image: url(${c:encodeURL('/1.jpg')});
color:blue;
}

And modify web.xml to add dsp support
<!-- ///////////// -->
<!-- DSP (optional) -->
<servlet>
<description><![CDATA[
The servlet loads the DSP pages.
]]></description>
<servlet-name>dspLoader</servlet-name>
<servlet-class>org.zkoss.web.servlet.dsp.InterpreterServlet</servlet-class>

<!-- Specify class-resource, if you want to access TLD defined in jar files -->
<init-param><param-name>class-resource</param-name><param-value>true</param-value></init-param>
</servlet>
<servlet-mapping>
<servlet-name>dspLoader</servlet-name>
<url-pattern>*.dsp</url-pattern>
</servlet-mapping>

Please refer to http://www.zkoss.org/doc/devguide-single/index.html#id4816000
for more information of DSP

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-05-13 07:59:03 +0800

Seen: 1,111 times

Last updated: May 13 '10

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