相关疑难解决方法(0)

JSF自定义转换器未调用null值

我在输出java.math.BigDecimal时创建了自定义Converter.当BigDecimal为0.00或null我想输出破折号时.

这是我的XHTML

<p:dataTable value="#{bean.data}" var="item">
    <p:column>
        <h:outputText value="#{item.currentValue}">
            <f:converter converterId="my.bigDecimalConverter" />
        </h:outputText>
    </p:column>
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是#{item.currentValue} 是未调用Converter中nullgetAsString方法.

@FacesConverter("my.bigDecimalConverter")
public class BigDecimalConverter implements Converter {

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (context == null || component == null) {
            throw new NullPointerException();
        }                

        if (value == null) {
            System.out.println("null=");
            return "--";
        }

        System.out.print("Class=" + value.getClass());

        if (value instanceof String) {
            System.out.println("Str=" + value);
            return (String) value;
        }

        if (value instanceof BigDecimal) …
Run Code Online (Sandbox Code Playgroud)

java jsf jsf-2

7
推荐指数
1
解决办法
2198
查看次数

标签 统计

java ×1

jsf ×1

jsf-2 ×1