0

自分の jsp タグで問題に直面しています。null 値を許可したいのですが、ハンドラーに null 値を与えたい場合、値は 0 で null ではありません。

私のハンドラー:

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);
}
}

私のタグライブラリ:

<?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 は null ですが、 に設定するBigDecimalStripperと 0 になります。

4

2 に答える 2

0

Tomcat のビルトイン EL パーサーは、Number を拡張するすべてのクラスに対してこれを行います。Tomcat 6.0.16 以降を使用している必要があります。これを試してください...

-Dorg.apache.el.parser.COERCE_TO_ZERO=false

于 2013-03-22T19:28:48.377 に答える