无法使用JSF,JavaEE

时间:2016-10-26 11:35:00

标签: java jsf

我试图自己解决,但是花了这么多时间才终于来到这里。我只想将用户的输入添加到数据库中,但我的create()方法不断获取NullPointerException。请告诉我它为什么以及我应该如何处理我的代码。吸气剂和二传手被排除在外。 谢谢。

Bb.java

@Named
@SessionScoped
public class Bb implements Serializable {

private Long id;
@NotNull
private String firstName;
@NotNull
private String lastName;
@NotNull
private String firstNameHurigana;
@NotNull
private String lastNameHurigana;
@NotNull
private String addressOne;
@NotNull
private String addressTwo;
@NotNull
private String birthYear;
@NotNull
private String birthMonth;
@NotNull
private String birthDay;
@NotNull
private String firstNameWife;
@NotNull
private String lastNameWife;
@NotNull
private String firstNameHuriganaWife;
@NotNull
private String lastNameHuriganaWife;
@NotNull
private String birthYearWife;
@NotNull
private String birthMonthWife;
@NotNull
private String birthDayWife;
@NotNull
private String housePhoneNumberOne;
@NotNull
private String housePhoneNumberTwo;
@NotNull
private String housePhoneNumberThree;
private String housePhoneNumber = housePhoneNumberOne + housePhoneNumberTwo + housePhoneNumberThree;
@NotNull
private String mobilePhoneNumberOne;
@NotNull
private String mobilePhoneNumberTwo;
@NotNull
private String mobilePhoneNumberThree;
private String mobilePhoneNumber = mobilePhoneNumberOne + mobilePhoneNumberTwo + mobilePhoneNumberThree;
@NotNull
private String mailAddress;




@Inject
transient Logger log;


public String goToInput() {
    System.out.println("back to input.");
    return "input.xhtml";
}

public String goToConfirm() {
    System.out.println("move to confirm page.");
    return "confirm.xhtml";
}

public String goToComplete() {
    OldCoupleInformationDb db = new OldCoupleInformationDb();

    OldCoupleInformation oci = new OldCoupleInformation(firstName, lastName,
            firstNameHurigana, lastNameHurigana, addressOne, addressTwo, birthYear,
            birthMonth, birthDay, firstNameWife, lastNameWife, firstNameHuriganaWife,
            lastNameHuriganaWife, birthYearWife, birthMonthWife, birthDayWife, housePhoneNumberOne,
            housePhoneNumberTwo, housePhoneNumberThree, mobilePhoneNumberOne, mobilePhoneNumberTwo,
            mobilePhoneNumberThree, mailAddress);
    System.out.println("move to complete page.");
    System.out.println(oci.toString());
    db.create(oci);
    return "complete.xhtml";
}
//create() was here

public void create(OldCoupleInformation oci) {
    OldCoupleInformationDb db = new OldCoupleInformationDb();

    try {
        System.out.println("#########################################################");
        System.out.println("ok1");
        db.create(oci);
        clear();
    } catch (Exception e) {
        System.out.println("miss");
        log.severe("新規登録できない/" + firstName);
    } finally {

    }
}

public void clear() {
    firstName = lastName
            = firstNameHurigana = lastNameHurigana = addressOne = addressTwo = birthYear
            = birthMonth = birthDay = firstNameWife = lastNameWife = firstNameHuriganaWife
            = lastNameHuriganaWife = birthYearWife = birthMonthWife = birthDayWife = housePhoneNumberOne
            = housePhoneNumberTwo = housePhoneNumberThree = mobilePhoneNumberOne = mobilePhoneNumberTwo
            = mobilePhoneNumberThree = mailAddress = null;
}

OldCoupleInformation.java

@Entity

@Table(name =“KAGUYA”) 公共类OldCoupleInformation实现Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotNull
private String firstName;
@NotNull
private String lastName;
@NotNull
private String firstNameHurigana;
@NotNull
private String lastNameHurigana;
@NotNull
private String addressOne;
@NotNull
private String addressTwo;
@NotNull
private String birthYear;
@NotNull
private String birthMonth;
@NotNull
private String birthDay;
@NotNull
private String firstNameWife;
@NotNull
private String lastNameWife;
@NotNull
private String firstNameHuriganaWife;
@NotNull
private String lastNameHuriganaWife;
@NotNull
private String birthYearWife;
@NotNull
private String birthMonthWife;
@NotNull
private String birthDayWife;

@NotNull
private String housePhoneNumberOne;
@NotNull
private String housePhoneNumberTwo;
@NotNull
private String housePhoneNumberThree;
private String housePhoneNumber = housePhoneNumberOne + housePhoneNumberTwo + housePhoneNumberThree;
@NotNull
private String mobilePhoneNumberOne;
@NotNull
private String mobilePhoneNumberTwo;
@NotNull
private String mobilePhoneNumberThree;
private String mobilePhoneNumber = mobilePhoneNumberOne + mobilePhoneNumberTwo + mobilePhoneNumberThree;
@NotNull
private String mailAddress;




public OldCoupleInformation(String firstName, String lastName, String firstNameHurigana, String lastNameHurigana, String addressOne, String addressTwo, String birthYear, String birthMonth, String birthDay, String firstNameWife, String lastNameWife, String firstNameHuriganaWife, String lastNameHuriganaWife, String birthYearWife, String birthMonthWife, String birthDayWife, String housePhoneNumberOne, String housePhoneNumberTwo, String housePhoneNumberThree, String mobilePhoneNumberOne, String mobilePhoneNumberTwo, String mobilePhoneNumberThree, String mailAddress) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.firstNameHurigana = firstNameHurigana;
    this.lastNameHurigana = lastNameHurigana;
    this.addressOne = addressOne;
    this.addressTwo = addressTwo;
    this.birthYear = birthYear;
    this.birthMonth = birthMonth;
    this.birthDay = birthDay;
    this.firstNameWife = firstNameWife;
    this.lastNameWife = lastNameWife;
    this.firstNameHuriganaWife = firstNameHuriganaWife;
    this.lastNameHuriganaWife = lastNameHuriganaWife;
    this.birthYearWife = birthYearWife;
    this.birthMonthWife = birthMonthWife;
    this.birthDayWife = birthDayWife;
    this.housePhoneNumberOne = housePhoneNumberOne;
    this.housePhoneNumberTwo = housePhoneNumberTwo;
    this.housePhoneNumberThree = housePhoneNumberThree;
    this.mobilePhoneNumberOne = mobilePhoneNumberOne;
    this.mobilePhoneNumberTwo = mobilePhoneNumberTwo;
    this.mobilePhoneNumberThree = mobilePhoneNumberThree;
    this.mailAddress = mailAddress;
}

public OldCoupleInformation() {
}

OldCoupleInformationDb

@Stateless

公共类OldCoupleInformationDb {

@PersistenceContext
private EntityManager em;

public void create(OldCoupleInformation oldCoupleInformation) {
    System.out.println(em);
    System.out.println("########################################################################");
    em.persist(oldCoupleInformation);

}

}

错误

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)
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)
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:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)

引起:java.lang.NullPointerException     at com.sun.common.util.logging.LoggingOutputStream $ LoggingPrintStream.println(LoggingOutputStream.java:228)     在org.apache.felix.gogo.runtime.threadio.ThreadPrintStream.println(ThreadPrintStream.java:205)     在Db.OldCoupleInformationDb.create(OldCoupleInformationDb.java:25)     在Db.Bb.create(Bb.java:126)     在Db.Bb.goToComplete(Bb.java:102)     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:498)     在javax.el.E​​LUtil.invokeMethod(ELUtil.java:332)     在javax.el.BeanELResolver.invoke(BeanELResolver.java:537)     在javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)     在com.sun.el.parser.AstValue.invoke(AstValue.java:283)     at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)     在org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)     在org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)     at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)     在javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)     ......还有36个

1 个答案:

答案 0 :(得分:0)

看起来你的create()方法定义不带任何参数,但是当你使用它时你在create(oci)中有一个参数。尝试使用不带参数oci的create()。