[英]JSTL <c:if> tag - Checking whether Java Bean method returns True
I currently have a .jsp
file as follows (partly shown): 我目前有一个
.jsp
文件,如下所示(部分显示):
<jsp:useBean id="cart" class="edu.unsw.comp9321.assignment1.CartBean"
scope="session" />
<tr>
<td><input type="submit" name="cartBtn" value="Go To Checkout"/></td>
<td><input type="submit" name="cartBtn" value="Remove From Cart"/></td>
<c:if test="${cart.isCartListEmpty eq true}">
<td><input type="submit" name="cartBtn" value="Back To Search"/></td>
</c:if>
</tr>
The bean cart
has the code: Bean
cart
具有以下代码:
public boolean isCartListEmpty(){
if (this.cart.isEmpty())
return true;
return false;
}
The problem is I am getting an error with the following line: 问题是我在以下行出现错误:
<c:if test="${cart.isCartListEmpty eq true}">
Could someone please tell me the correct way to evaluate whether the bean method is returning true
or false
? 有人可以告诉我评估bean方法返回的是
true
还是false
的正确方法吗?
Thank you for your help. 谢谢您的帮助。
The EL ${bean.attribute}
will try to call the method getAttribute()
or isAttribute()
of the bean
. EL
${bean.attribute}
将尝试调用bean
getAttribute()
或isAttribute()
方法。
So in your case, ${cart.isCartListEmpty}
will look for a method getIsCartListEmpty()
or isIsCartListEmpty()
in your cart
. 因此,在您的情况下,
${cart.isCartListEmpty}
将在cart
寻找getIsCartListEmpty()
或isIsCartListEmpty()
方法。
What you need is thus ${cart.cartListEmpty}
to call the appripriate isCartListEmpty()
method. 因此,您需要的是
${cart.cartListEmpty}
来调用适当的isCartListEmpty()
方法。
Side notes: 旁注:
eq true
part since isCartListEmpty()
already returns a boolean. eq true
部分,因为isCartListEmpty()
已经返回了一个布尔值。 isCartListEmpty()
method body to return this.cart.isEmpty()
. isCartListEmpty()
方法主体以return this.cart.isEmpty()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.