Encoding URLs"
From Documentation
Tmillsclare (talk | contribs) m (Created page with 'A XHTML component generates attributes directly to native HTML tags. It means, unlike XUL, it doesn't prefix the servlet context path to attributes for specifying URL. For exampl…') |
(fix taglib url) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | A XHTML component generates attributes directly to native HTML tags. It means, unlike XUL, it doesn't prefix the servlet context path to attributes for specifying URL. For example, the following codes | + | {{ZKComponentReferencePageHeader}} |
+ | |||
+ | A XHTML component generates attributes directly to native HTML tags. It means, unlike XUL, it doesn't prefix the servlet context path to attributes for specifying URL. For example, the following codes will not work (unless the servlet context is ""). | ||
<source lang="xml" > | <source lang="xml" > | ||
Line 9: | Line 11: | ||
<source lang="xml" > | <source lang="xml" > | ||
− | <?taglib uri="http://www.zkoss.org/dsp/web/core | + | <?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="p"?> |
... | ... | ||
<img href="${p:encodeURL('/my/good.png')}"/> | <img href="${p:encodeURL('/my/good.png')}"/> | ||
Line 27: | Line 29: | ||
Notice that XUL components and all ZK features that accept a URL will invoke the <mp>encodeURL</mp> method automatically. The reason why we do not | Notice that XUL components and all ZK features that accept a URL will invoke the <mp>encodeURL</mp> method automatically. The reason why we do not | ||
handle XHTML components is that we do not know which attribute requires a URL. | handle XHTML components is that we do not know which attribute requires a URL. | ||
+ | |||
+ | {{ZKComponentReferencePageFooter}} |
Latest revision as of 01:43, 4 February 2016
A XHTML component generates attributes directly to native HTML tags. It means, unlike XUL, it doesn't prefix the servlet context path to attributes for specifying URL. For example, the following codes will not work (unless the servlet context is "").
<img href="/my/good.png"/>
Instead, you should use the encodeURL function in EL expressions as follows.
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="p"?>
...
<img href="${p:encodeURL('/my/good.png')}"/>
In Java, you should use the method, Execution.encodeURL(String).
<img id="another"/>
<zscript>
another.setDynamicAttribute("href",
Executions.getCurrent().encodeURL("/my/good.png"));
</zscript>
Notice that XUL components and all ZK features that accept a URL will invoke the encodeURL method automatically. The reason why we do not handle XHTML components is that we do not know which attribute requires a URL.