开发者

Acessing the name attribute of a <ui:insert>

开发者 https://www.devze.com 2023-02-24 17:29 出处:网络
I have a JSF template with the a title and a subtitle : <h3><ui:insert name=\"title\"/></h3>

I have a JSF template with the a title and a subtitle :

<h3><ui:insert name="title"/></h3>
<hr/>
<h5><ui:insert name="subtitle"/></h5>

All the pages using this template have title, but开发者_运维百科 not always a subtitle :

<ui:define name="title">My Title with no subtitle</ui:define>

When there is no subtitle I don't want to have a <hr/> tag. So what I really want to do is check if subtitle is empty, if yes, ignore the block of code. Something like that :

<h3><ui:insert name="title"/></h3>
<c:if test="#{not empty subtitle}">
    <hr/>
    <h5><ui:insert name="subtitle"/></h5>
<c:if>

But of course <c:if test="#{not empty subtitle}"> doesn't work. I don't know how to access the value of the subtitle variable.

Any idea ?

Thanks


Closest what you can get is to define the subtitle as an <ui:param> instead.

Thus,

<ui:define name="title">My Title with a subtitle</ui:define>
<ui:param name="subtitle" value="A subtitle" />

with

<h3><ui:insert name="title"/></h3>
<ui:fragment rendered="#{not empty subtitle}">
    <hr/>
    <h5>#{subtitle}</h5>
</ui:fragment>
0

精彩评论

暂无评论...
验证码 换一张
取 消