JSF2 ignores empty alt attribute

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, the web client receives an HTML page without the empty alt attribute in the img element:

<!-- Yandex.Metrika -->
<img src="//mc.yandex.ru/watch/xxx" />
<!-- /Yandex.Metrika -->

As a result, my document had a validation error (

How can I solve this problem?

+5
source share
2 answers

You can use the JIF graphicImage component, which displays an empty alt attribute.

Example:

<h:graphicImage value="#{resource['images:image1.png']}" alt="" />

or

<h:graphicImage value="http://somedomain.com/somecontext/xxx/image1.png" alt="" />
+1
source

Not sure if this is a bug in JSF2 (JSF1.2 saves empty attributes). To "bypass" that in JSF2, the wrapping code f:verbatimis like this:

<f:verbatim>
   <img src="//mc.yandex.ru/watch/xxx" alt=""/>
</f:verbatim>
0
source

All Articles