我有一个 jsf 片段:
<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>
但是当我使用它时,网络客户端在 img 元素中获取没有空 alt 属性的 HTML 页面:
<!-- Yandex.Metrika -->
<img src="//mc.yandex.ru/watch/xxx" />
<!-- /Yandex.Metrika -->
结果我的文档有验证错误(
我怎么解决这个问题?
最佳答案
您可以使用 JSF graphicsImage 组件,它会呈现空的 alt 属性。
例如:
<h:graphicImage value="#{resource['images:image1.png']}" alt="" />
或者
<h:graphicImage value="http://somedomain.com/somecontext/xxx/image1.png" alt="" />
关于jsf-2 - JSF2 忽略空 alt 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4092849/