目标无法访问,标识符' inputNew"'解析为null

时间:2014-06-18 15:25:36

标签: jsf

我想创建一个将值输入MySQL数据库的表单。我在代码中一直收到此错误:

Target Unreachable, identifier 'inputNew' resolved to null

有任何疑问可能是什么问题?

这是我的index.xhtml代码:

<h:form>
    <div class="input">
        <span class="group">Ime :</span>
        <h:inputText class="control" value="#{inputNew.prijava.ime}">
            <f:validateRegex pattern="^[a-zA-Z]{1,}$" />
        </h:inputText>
    </div>
    <h:commandButton action="#{inputNew.New}" value="Submit" class="button"/>
</h:form >

这是我的inputNew.java代码:

@Named(value = "inputNew")
@RequestScoped 
public class InputNew{
    @EJB
    private Bean bean;
    private Korisnik prijava =new Korisnik();
    private FacesContext cont = FacesContext.getCurrentInstance();

    public InputNew() {
    }

    public Korisnik getPrijava() {
        return prijava;
    }

    public void setPrijava(Korisnik prijava) {
        this.prijava = prijava;
    }

    public void New(){
        prijava = bean.addKorisnik(prijava);
        if (prijava == null) {
            cont.addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO,
                    "Success.",null));
        } else {
            cont.addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR,
                    "Error: "+prijava.getUsername(),null));
        }
    }
}

这是Stack Trace:

javax.el.PropertyNotFoundException: /index.xhtml @67,126 value="#{inputNew.prijava.ime}": Target Unreachable, identifier 'inputNew' resolved to null
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046)
    at javax.faces.component.UIInput.validate(UIInput.java:976)
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1249)
    at javax.faces.component.UIInput.processValidators(UIInput.java:712)
    at javax.faces.component.UIForm.processValidators(UIForm.java:253)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
    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.el.PropertyNotFoundException: Target Unreachable, identifier 'inputNew' resolved to null
    at com.sun.el.parser.AstValue.getTarget(AstValue.java:174)
    at com.sun.el.parser.AstValue.getType(AstValue.java:86)
    at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201)
    at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93)
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
    ... 40 more

3 个答案:

答案 0 :(得分:0)

堆栈跟踪的第一行解释了问题:

  

javax.el.PropertyNotFoundException:/ index.xhtml @ 67,126 value="#{inputNew.prijava.ime}":目标无法访问,标识符&#39; inputNew&#39;已解决为null

似乎getPrijava()方法返回的元素没有ime字段的getter / setter。验证Korisnik类是否具有ime字段和正确的getter / setter。


由于您正在使用CDI,因此请务必从正确的套餐中导入@RequestScoped

  • javax.faces.bean来自JSF,应与@ManagedBean
  • 一起使用
  • javax.enterprise.context来自CDI,应与@Named一起使用。

相应地修复您的导入。

答案 1 :(得分:0)

@Named的来源并不明显,但@RequestScoped建议您尝试使用JSF托管bean。改为

@ManagedBean
@RequestScoped
public class InputNew {
    ...
}

答案 2 :(得分:0)

从我在这方面的小经验。在某些情况下代码:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name="logedUser")
@SessionScoped
public class LogedUser implements Serializable{

产生下一个错误:

javax.el.MethodNotFoundException: /login.xhtml @28,126 action="#{logedUser.odjavi}": Method not found: beans.LogedUser@7a9af561.odjavi()

当我将代码更改为代码时:

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

@Named//(value = "registrationBean")
@RequestScoped
public class LogedUser implements Serializable{

Everithing还可以。