简体   繁体   中英

JSF Custom Tags - can they be used conditionally?

I can neither find a direct answer to this, nor perhaps figure out how to word this, but I'm trying to achieve a conditional using JSF's "custom tags". I've made a stripped down arbitrary example to demonstrate:

<ui:composition xmlns:mytag="http://my.tag/this">
    <c:choose>
        <c:when test="mytag:this">
            <mytag:this>
        </c:when>
        <c:otherwise>
            <div>this page</div>
        </c:otherwise>
    </c:choose>
</ui:composition>

This would be in the context of a taglib reference only including the custom tag if the source was available. The exact scenario would be where a page could be overridden dynamically, if it exists, or otherwise show the 'otherwise' content.

I've not had much look with getting this to compile with my 'stab-in-the-dark' methodology so far (in lieu of seeing any examples of this done).

Am I trying to look for a solution that isn't possible?

It's been years since I worked with JSF, but if I recall correctly custom "tags" can only be used as HTML tags, but not within EL expressions.

For use within an EL expression, you could create a custom EL function . Then you could write:

<c:when test="#{yourFunction()}">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM