Apache Tapestry-IF具有多个条件

问题描述 投票:4回答:3

我需要在一个Tapestry表列中获得2个Java字段。我的每个字段都可以为空。是否可以在单行中写条件(一个IF运算符中有2个字段),或者我必须为第二个字段写内部条件?

现在我有这个:

<t:if test="${subject.subjectQuantity}">
    <t:if test="${subject.unitMeasure}">
        <tr>
            <td>Subject count:</td>
            <td>${subject.subjectQuantity} ${subject.unitMeasure}</td>
        </tr>
    </t:if>
</t:if>
if-statement tapestry
3个回答
5
投票

JAVA

public boolean isSubjectQuantityAndUnitMeasurePopulated() {
    return subject.subjectQuantity != null && subject.unitMeasure != null;
}

TML

<t:if test="subjectQuantityAndUnitMeasurePopulated">
    <tr>
        <td>Subject count:</td>
        <td>${subject.subjectQuantity} ${subject.unitMeasure}</td>
    </tr>
</t:if>

0
投票

这是何时将逻辑放在组件类而不是模板中的一个很好的例子。只需创建一个getter即可返回要显示的String。将您的条件放入该吸气器。


0
投票

您可以在Java代码中没有任何条件。请参考下面的代码。

Scrub.tml

  <t:if test="sitelistUtility">
        <label> ${sitelist.utility.name}</label>
  </t:if>

Scrub.java

public boolean isSitelistUtility() {
      return sitelist != null && sitelist.getUtility() != null;
  }
© www.soinside.com 2019 - 2024. All rights reserved.