h:commandButton抛出nullpointerException

时间:2014-08-09 00:44:07

标签: jsf nullpointerexception richfaces commandbutton

我想为产品添加新的出价,但出于某种原因,当我点击该按钮时,会抛出nullpointerexception。我尝试了不同的东西,但似乎都没有。我正在使用richfaces 4.3.7.Final

我的xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
 <!DOCTYPE html>
 <html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:f="http://xmlns.jcp.org/jsf/core"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:a4j="http://richfaces.org/a4j">
  <h:body>
    <ui:composition template="../template.xhtml">
        <ui:define name="content">

            <rich:tabPanel switchType="client">
                <rich:tab name="Details">
                    <h:form>
                    <rich:panel>
                    <h:panelGrid columns="2" id="registerGroupPanel">                
                        <h:outputLabel value="#{msg.productName}"/>
                        <h:outputLabel value="#{repairDetailsBean.selectedRepair.item.productName}"/>

                        <h:outputLabel value="#{msg.description}"/>
                        <h:outputLabel value="#{repairDetailsBean.selectedRepair.details.description}"/>

                        <h:outputLabel value="#{msg.category}"/>
                        <h:outputLabel value="#{repairDetailsBean.selectedRepair.item.category}"/>

                        <h:outputLabel value="#{msg.brand}"/>
                        <h:outputLabel value="#{repairDetailsBean.selectedRepair.item.brand}"/>

                        <h:outputLabel value="#{msg.defect}"/>
                        <h:outputLabel value="#{repairDetailsBean.selectedRepair.details.defect}"/>

                        <h:outputLabel value="#{msg.priceModel}"/>
                        <h:outputLabel value="#{repairDetailsBean.selectedRepair.details.priceModel}"/>

                        <h:outputLabel value="#{msg.bidDueDate}"/>
                        <h:outputLabel value="#{repairDetailsBean.selectedRepair.details.dueDate.toGregorianCalendar().time.toGMTString()}">
                            <f:convertDateTime pattern="dd-MM-yyyy HH:mm" />
                        </h:outputLabel>

                    </h:panelGrid>
                </rich:panel>
                    </h:form>


                </rich:tab>
                <rich:tab name="Bids">
                    <h:form>
                    <rich:panel>
                        <h:panelGrid columns="2" id="registerGroupPanel">
                            <rich:dataTable value="#{repairDetailsBean.bids}" var="bid" rows="25" id="table">
                    <rich:column>
                        <f:facet name="header">
                            <h:panelGroup>
                                <h:outputText value="Repairer name"/>
                            </h:panelGroup>
                        </f:facet>
                        <h:outputText value="#{bid.getRepairer().getPerson().getFirstname()} #{bid.getRepairer().getPerson().getLastname()}"/>
                    </rich:column>

                    <rich:column>
                        <f:facet name="header">
                            <h:panelGroup>
                                <h:outputText value="Rating"/>
                            </h:panelGroup>
                        </f:facet>
                        <h:outputText value="#{bid.getRepairer().getOveralRating()}"/>
                    </rich:column>

                    <rich:column>
                        <f:facet name="header">
                            <h:panelGroup>
                                <h:outputText value="Price"/>
                            </h:panelGroup>
                        </f:facet>
                        <h:outputText value="#{bid.price}"/>
                    </rich:column>
                </rich:dataTable>
                        </h:panelGrid> 
                    </rich:panel>
                    </h:form>
                 </rich:tab>

                <rich:tab name="Add bid">
                    <h:form>
                    <rich:panel>
                        <p>Bid price</p>
                        <rich:inputNumberSpinner id="price" value="#{repairDetailsBean.price}">
                            <f:validateRequired />
                            <rich:validator/>
                        </rich:inputNumberSpinner>
                        <rich:message for="price" style="color: red;"/>   

                        <p></p>
                        <a4j:commandButton value="Submit" action="#{repairDetailsBean.placeNewBid}"/>
                        <h:commandButton action="#{repairDetailsBean.placeNewBid}" value="Place new bid">
                            <param name="faces-redirect" value="true"/>
                        </h:commandButton>
                        <h:commandButton action="#{repairDetailsBean.placeNewBid()}" value="Place new bid met haakjes">
                            <param name="faces-redirect" value="true"/>
                        </h:commandButton>

                    </rich:panel>
                    </h:form>


                </rich:tab>
            </rich:tabPanel>
        </ui:define>
    </ui:composition>
</h:body>
</html>

我的豆子

@Component("repairDetailsBean")
@Scope("session")
public class RepairDetailsBean implements Serializable{
private Repair selectedRepair;

private Date date;

private List<Bid> bids;

private Bid bid;

private double price = 0.0;

private RepairService repairService;

private User user;
private Repairer repairer;

@Autowired
@Qualifier("userBean")
private UserBean userBean;

private UserService userService;

public void initRepairDetails(){
    setBids(selectedRepair.getBids());
}

public void formatDate(){
    setDate(selectedRepair.getDetails().getDueDate().toGregorianCalendar().getTime());
}

public String placeNewBid(){        
    try {
        user = userService.getUser(userBean.getUsername());
    } catch (UserServiceException ex) {
        Logger.getLogger(RepairDetailsBean.class.getName()).log(Level.SEVERE, null, ex);
    }
    repairer = (Repairer) user;



    repairService.placeBid(repairer, selectedRepair, price);

    return "placeBidCompleted";
} 

错误消息

FATAL:   JSF1073: javax.faces.FacesException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=, Message=#{repairDetailsBean.placeNewBid()}: java.lang.NullPointerException
FATAL:   #{repairDetailsBean.placeNewBid()}: java.lang.NullPointerException
javax.faces.FacesException: #{repairDetailsBean.placeNewBid()}: java.lang.NullPointerException
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:89)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.faces.FacesException: #{repairDetailsBean.placeNewBid()}: java.lang.NullPointerException
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
... 30 more
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:102)
... 34 more
Caused by: java.lang.NullPointerException
at be.kdg.repaircafe.beans.RepairDetailsBean.placeNewBid(RepairDetailsBean.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at javax.el.ELUtil.invokeMethod(ELUtil.java:326)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:536)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
at com.sun.el.parser.AstValue.invoke(AstValue.java:269)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 35 more

1 个答案:

答案 0 :(得分:0)

您的repairService显然为null,如果您启用了CDI,或者至少需要手动实例化,则需要通过添加@Inject正确注入。