2

我在这样的复合组件中有 ah:graphicImage:

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

但是,如果未设置某些属性(例如宽度、高度),则它们会被渲染为空,这很有效。在win7上的IE9中,这会导致img标签的宽度和高度属性被渲染为1。所以图像有1px的宽度和1px的高度。

4

1 回答 1

3

您可以通过 有条件地添加属性<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>

也可以看看:

于 2015-11-02T10:07:42.737 回答