2

I have a h:graphicImage in a composite component like this:

<composite:interface>
    <composite:attribute name="name" required="true" type="java.lang.String" />
    <composite:attribute name="alt" required="false" type="java.lang.String" />
    <composite:attribute name="height" required="false" type="java.lang.String" />
    <composite:attribute name="width" required="false" type="java.lang.String" />
</composite:interface>

<composite:implementation>

    <h:graphicImage url="something-common#{cc.attrs.name}"
                alt="#{cc.attrs.alt}"
                height="#{cc.attrs.height}"
                width="#{cc.attrs.width}" />

</composite:implementation>

This works, however, if some attributes are not set (e.g. width, height) they are rendered empty. In IE9 on win7 this causes the img tag width and height attribute to be rendered as 1. So the images have 1px width and 1px height.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Filip Majernik
  • 7,700
  • 13
  • 45
  • 53

1 Answers1

3

You can conditionally add attributes via <c:if><f:attribute>.

<h:graphicImage ...>
    <c:if test="#{not empty cc.attrs.height}"><f:attribute name="height" value="#{cc.attrs.height}" /></c:if>
    <c:if test="#{not empty cc.attrs.width}"><f:attribute name="width" value="#{cc.attrs.width}" /></c:if>
</h:graphicImage>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you very much. But this wouldn't probably work if for example the width attribute is computed in a backing bean and the component gets rerendered/updated upon an ajax request, am I right? – Filip Majernik Nov 02 '15 at 10:20
  • It will indeed only work if the view is implicitly/explicitly rebuilt at that point. That depends on your specific case. Just try and see if it works in your specific case. The alternative would be to override and customize the renderer. – BalusC Nov 02 '15 at 10:45