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.

1 Answer 1

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:

Sign up to request clarification or add additional context in comments.

2 Comments

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?
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.