質問

I've made a composite component which seems to works fine if used in a "static" way but it doesn't work if I bind one of its attributes to an expression.

If I use my component like

<ez:indicadorEstadoSubsistema subSystemName="Server" status="someIntLiteral"/>

works fine but I need to use it in a more dynamic way, like

<ez:indicadorEstadoSubsistema subSystemName="Server" status="#{serverData.status}"/>.

I've read that JSTL tags run on view build time instead view rendering time, so thats maybe the reason I'm not getting the status expression bind evaluated at the right time, but I don't know how to workaround this.

My component is just an image with a tooltip. Both of them depend on the "status" attribute value.

Component

<cc:interface>
    <cc:attribute name="status" shortDescription="Represents the SubSystem status." required="true" default="1" type="java.lang.Integer"/>
    <cc:attribute name="subSystemName" required="true" type="java.lang.String"/>
</cc:interface>

<cc:implementation>
    <c:choose>
        <c:when test="#{cc.attrs.status eq 0}">
            <h:graphicImage id="icon" value="#{resource['images:delete.png']}" width="16" height="16"/>
            <c:set var="message" value="#{cc.attrs.subSystemName} subsystem doesn't responds."/>
        </c:when>
        <c:when test="#{cc.attrs.status eq 1}">
            <h:graphicImage id="icon" value="#{resource['images:delete.png']}" width="16" height="16"/>
            <c:set var="message" value="Unconsistent status."/>
        </c:when>
        <c:when test="#{cc.attrs.status eq 2}">
            <h:graphicImage id="icon" value="#{resource['images:warning.png']}" width="16" height="16"/>
            <c:set var="message" value="#{cc.attrs.subSystemName} system not working properly."/>
        </c:when>
        <c:when test="#{cc.attrs.status eq 3}">
            <h:graphicImage id="icon" value="#{resource['images:check.png']}" width="16" height="16"/>
            <c:set var="message" value="#{cc.attrs.subSystemName} system works fine."/>
        </c:when>
    </c:choose>
    <p:tooltip for="icon" value="#{message}" showEffect="fade" hideEffect="fade" />  
</cc:implementation>

Thank you.

役に立ちましたか?

解決

Generally, it's not a good idea to use JSTL tags in JSF. Why don't you use <h:panelGroup>? Try something like this:

<h:panelGroup rendered="#{cc.attrs.status eq 0}">
    <h:graphicImage id="icon" value="#{resource['images:delete.png']}" width="16" height="16"/>
    <ui:param var="message" value="#{cc.attrs.subSystemName} subsystem doesn't responds."/>
</h:panelGroup>
<p:tooltip for="icon" value="#{message}" showEffect="fade" hideEffect="fade" />
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top