if-statementtapestry

Apache Tapestry - IF with several conditions


I need to get 2 java fields in the one Tapestry table column. Every of my fields can be null. Can I write if condition in single line (2 fields in one IF operator), or I must write inner condition for second field?

Now I have this:

<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>

Solution

  • 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>