【发布时间】:2016-04-18 10:43:20
【问题描述】:
在使用 JSF、JSTL 和 Trinidad 创建的页面上,我有一些带有许多属性的标签。
<tr:selectBooleanRadio
group="#{groupId}"
id="#{groupId}_#{Id}_radio"
selected="#{value.yesterday}"
text="#{msg.ib_selectTimeIntervalRadio_yesterday_label}"
shortDesc="#{ib:fn_coalesce(title,label)}"
simple="#{ib:fn_coalesce(simple,true)}"
styleClass="#{ib:fn_coalesce(styleClass,'selectTimeIntervalRadio')}"/>
我想在<td> 元素中或直接有条件地显示它。现在我这样做:
<c:when test="#{not horizontal}">
<tr>
<td>
<tr....>
</td>
</tr>
</c:when>
<c:when test="#{horizontal}">
<tr...>
</c:when>
这样我重复同一段代码两次,这显然很糟糕。我能做什么?
恕我直言,为 tr... 调用创建一个新的自定义组件是没有用的 - 调用它会遇到所有相同的问题。
也许,我可以有条件地将一个标签封装在另一个标签中?可以吗?
另一种方式可能是:将 tr... 标记放在某种变量中,并在使用此变量构造时使用相同的标记。也许,有可能?
你知道如何避免这种重复代码的另一种方法吗?
【问题讨论】:
标签: html jsf jstl trinidad conditional-rendering