访问< ui:insert>的name属性 [英] Acessing the name attribute of a <ui:insert>
问题描述
我有一个带有标题和副标题的JSF模板:
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>
没有字幕时,我不想有<hr/>
标记.因此,我真正想做的是检查subtitle
是否为空,如果是,则忽略代码块.像这样的东西:
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>
但是<c:if test="#{not empty subtitle}">
当然不起作用.我不知道如何访问subtitle
变量的值.
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.
有什么主意吗?
谢谢
推荐答案
最接近的方法是将字幕定义为<ui:param>
.
Closest what you can get is to define the subtitle as an <ui:param>
instead.
因此
<ui:define name="title">My Title with a subtitle</ui:define>
<ui:param name="subtitle" value="A subtitle" />
使用
<h3><ui:insert name="title"/></h3>
<ui:fragment rendered="#{not empty subtitle}">
<hr/>
<h5>#{subtitle}</h5>
</ui:fragment>
这篇关于访问< ui:insert>的name属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!