I have a jsf snippet:
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui=开发者_如何学编程"http://java.sun.com/jsf/facelets">
<!-- Yandex.Metrika -->
<img src="//mc.yandex.ru/watch/xxx" alt=""/>
<!-- /Yandex.Metrika -->
</ui:composition>
But when I use it, web-client get HTML page whithout empty alt attribute in img element:
<!-- Yandex.Metrika -->
<img src="//mc.yandex.ru/watch/xxx" />
<!-- /Yandex.Metrika -->
As result my document has validation error (
How can I solve this problem?
You could use the JSF graphicImage component, which does render the empty alt attribute.
For Example:
<h:graphicImage value="#{resource['images:image1.png']}" alt="" />
or
<h:graphicImage value="http://somedomain.com/somecontext/xxx/image1.png" alt="" />
Not sure if that is a bug in JSF2 (JSF1.2 preserves empty attributes).
To 'workaround' that in JSF2, wrap code by f:verbatim
, like this:
<f:verbatim>
<img src="//mc.yandex.ru/watch/xxx" alt=""/>
</f:verbatim>
精彩评论