java.lang.NullPointerException PrimeFaces自动完成

时间:2014-05-09 00:53:56

标签: jsf primefaces autocomplete

我遇到自动完成素数问题,我骑这个板子别无选择但只能创建一个新帖子。

self的值来完成Nullo my ManagedBean,遵循带错误的代码

<p:fieldset id="campos" legend="Pleito"  styleClass="ui-fieldset-legend">
        <h:panelGrid columns="2"  columnClasses="colunaEsquerda,colunaDireita">
            <h:outputLabel value="id:" />
            <h:inputText value="#{pleitoBean.entity.id}" disabled="#{pleitoBean.currentStateName != 'SEARCH'}" style="width: 80px;"
            styleClass="inputText" onkeypress="return SomenteNumero(event)"/>

            <h:outputLabel value="Estado:" />
            <p:autoComplete id="autoComplete" value="#{pleitoBean.estado}"
            completeMethod="#{pleitoBean.sugerirPaises}"
            forceSelection="true" converter="estadoConverter"
            var="p" itemLabel="#{p.nome}" itemValue="#{estado}" >


            </p:autoComplete>

            <h:outputLabel value="Data Pleito:" />
            <p:calendar locale="pt" 
                showButtonPanel="true" navigator="true" selectOtherMonths="true"
                pattern="dd/MM/yyyy"  
                value="#{pleitoBean.entity.dataPleito}" style="width: 90px;"/>

        </h:panelGrid>
</p:fieldset>

转换器

@FacesConverter("estadoConverter")
public class EstadoConverter implements Converter{

    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Integer codigo = null;

        try {
            //System.out.println("getAsObject: " + value);
            codigo = Integer.valueOf(value);
        } catch (NumberFormatException e) { }

        if (value != null) {
            for (Estado estado : PleitoBean.listEstados) {
                if (codigo.equals(estado.getId())) {
                    return estado;
                }
            }
        }
        return null;
    }

    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value != null && !value.equals("")) {
            Estado pais = (Estado) value;
            return String.valueOf(pais.getId());
        }
        return null;
    }

}

ManagedBean

static{
        try {
            listEstados = estadoLogic.findAll(new Estado());
        } catch (BusinessException e) {
            e.printStackTrace();
        }
    }


public List<Estado> sugerirEstados(String consulta) {
    List<Estado> estadosSugeridos = new ArrayList<Estado>();

    for (Estado estado : listEstados) {
        if (estado.getNome().toLowerCase().startsWith(consulta.toLowerCase())) {
            estadosSugeridos.add(estado);
        }
    }

    return estadosSugeridos;
}

最后发生的错误

javax.faces.FacesException: #{pleitoBean.save}: java.lang.NullPointerException
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:117)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:795)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1260)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:101)
... 23 more




Caused by: java.lang.NullPointerException
at com.observatorioLegislativo.bean.PleitoBean.save(PleitoBean.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 24 more

0 个答案:

没有答案