0
我正面臨着我自己的jsp標記的問題。我希望它允許空值,但如果我想爲我的處理程序提供空值,則值爲0並且不爲空。JSP自定義標籤空值
我的處理程序:
public class BigDecimalStripper extends SimpleTagSupport {
private BigDecimal numberToStrip;
public void setNumberToStrip(BigDecimal numberToStrip) {
this.numberToStrip = numberToStrip;
}
@Override
public void doTag() throws JspException, IOException {
if (numberToStrip == null) {
return;
}
JspWriter out = getJspContext().getOut();
BigDecimal withoutTrailingZeros = numberToStrip.stripTrailingZeros();
String formattedNumber = withoutTrailingZeros.toPlainString();
out.println(formattedNumber);
}
}
我的taglib:
<?xml version="1.0" encoding="UTF-8" ?>
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>2.0</jsp-version>
<short-name>Fishie JSP Utils</short-name>
<tag>
<name>BigDecimalStrip</name>
<tag-class>ch.fishie.jsp.utils.BigDecimalStripper</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>numberToStrip</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
我的JSP代碼:
<c:forEach items="${pagination.pageEntries}" var="aquarium">
<tr>
<td class="name"><c:out value="${aquarium.name}" /></td>
<td class="length"><fu:BigDecimalStrip numberToStrip="${aquarium.length}" /></td>
.....
aquarium.length爲空,但是當它是設置爲BigDecimalStripper
,它是0. 有人看到我犯的錯誤嗎?