1
 Error Rendering View[test.xhtml]
                                 java.lang.NullPointerException
    at org.primefaces.component.orderlist.OrderListRenderer.encodeOptions(OrderListRenderer.java:149)
    at org.primefaces.component.orderlist.OrderListRenderer.encodeList(OrderListRenderer.java:108)
    at org.primefaces.component.orderlist.OrderListRenderer.encodeMarkup(OrderListRenderer.java:79)
    at org.primefaces.component.orderlist.OrderListRenderer.encodeEnd(OrderListRenderer.java:49)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
    at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChild(RendererUtils.java:543)
    at org.apache.myfaces.shared_impl.renderkit.html.HtmlGridRendererBase.renderChildren(HtmlGridRendererBase.java:315)
    at org.apache.myfaces.shared_impl.renderkit.html.HtmlGridRendererBase.encodeEnd(HtmlGridRendererBase.java:150)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:60)
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:44)
    at org.primefaces.component.dialog.DialogRenderer.encodeContent(DialogRenderer.java:174)
    at org.primefaces.component.dialog.DialogRenderer.encodeMarkup(DialogRenderer.java:103)
    at org.primefaces.component.dialog.DialogRenderer.encodeEnd(DialogRenderer.java:41)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:626)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:622)
    at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeEnd(AccordionPanelRenderer.java:60)

@FacesConverter("contactConverter") 公共类 ContactConverter 实现 Converter{

@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2)
        throws ConverterException {
    // TODO Auto-generated method stub
    TestBean tb= new TestBean();
    tb.setName(arg2);
    return tb;
}

@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2)
        throws ConverterException {
    // TODO Auto-generated method stub
    return arg2.toString();
}

我正在使用 primefaces 订单列表示例。但我正面临这个空指针异常。谷歌搜索后,我发现这个问题与转换器有关,但我不确定。任何人都可以帮助我使用转换器的简单 primeface 订单列表。

4

1 回答 1

2
java.lang.NullPointerException
    at org.primefaces.component.orderlist.OrderListRenderer.encodeOptions(OrderListRenderer.java:149)
    at org.primefaces.component.orderlist.OrderListRenderer.encodeList(OrderListRenderer.java:108)

来自 PrimeFaces 3.4OrderListRenderer源代码:

90     protected void encodeList(FacesContext context, OrderList ol) throws IOException {
...
108        encodeOptions(context, ol, (List) ol.getValue());
...
115    }
...
143    @SuppressWarnings("unchecked")
144    protected void encodeOptions(FacesContext context, OrderList old, List model) throws IOException {
145        ResponseWriter writer = context.getResponseWriter();
146        String var = old.getVar();
147        Converter converter = old.getConverter();
148
149        for(Iterator it = model.iterator(); it.hasNext();) {

因此,modelisnull和因此这个异常会在<p:orderList value>isnull和你的#{testBean.contacts}return时发生null。确保它不是null. #{testBean}请注意,当在范围内找不到时也会发生这种情况。

于 2013-02-13T12:54:29.830 回答