2

I want to make a form which is going to input values into a MySQL database. I keep getting this error in my code:

Target Unreachable, identifier 'inputNew' resolved to null

Any clue what the problem could be?

Here is my index.xhtml code:

<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 >

Here is my inputNew.java code:

@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));
        }
    }
}

Here is 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
Josef E.
  • 2,069
  • 2
  • 12
  • 29
Srdan Ristic
  • 2,383
  • 5
  • 15
  • 23
  • Seems like a problem when creating a new instance of `InputNew` for the request. You should provide the full stacktrace to have better understanding of the problem. – Luiggi Mendoza Jun 18 '14 at 15:34

3 Answers3

1

The first line of the stacktrace explains the problem:

javax.el.PropertyNotFoundException: /index.xhtml @67,126 value="#{inputNew.prijava.ime}": Target Unreachable, identifier 'inputNew' resolved to null

Seems that the elements returned by getPrijava() method doesn't have a getter/setter for ime field. Verify if Korisnik class have an ime field and the right getter/setter.


Since you're using CDI, make sure you're importing @RequestScoped from the right package:

  • javax.faces.bean is from JSF and should be used altogether with @ManagedBean
  • javax.enterprise.context is from CDI and should be used altogether with @Named.

Fix your imports accordingly.

Luiggi Mendoza
  • 81,685
  • 14
  • 140
  • 306
  • I just checked it, and everything looks good in class Korisnik, attribute ime has getter and setter. – Srdan Ristic Jun 18 '14 at 16:10
  • I got it to work, I deleteed InputNew class and then added it again with @RequestScoped, after that I cleaned and built the whole project and everything worked...It's probably some kind of bug or something. Thanks for the answers. – Srdan Ristic Jun 18 '14 at 16:25
0

It isn't obvious what @Named comes from, but @RequestScoped suggest you try to use JSF managed beans. Change to

@ManagedBean
@RequestScoped
public class InputNew {
    ...
}
Tires
  • 1,153
  • 13
  • 22
  • `@Named` comes from CDI, which works fine to support managed beans to be used from JSF. – Luiggi Mendoza Jun 18 '14 at 15:53
  • Did you have to register some EL resolver? Obviously the problem results from 'inputNew' resolves to null. Thus inputNew has to be provided somehow to the resolver. Otherwise you would get another exception. – Tires Jun 18 '14 at 15:58
  • Because there's a property not found: `inputNew.prijava.ime`. Read the stacktrace. – Luiggi Mendoza Jun 18 '14 at 15:59
  • 1
    Yes there is a property not found, but there is a further cause "Target Unreachable, identifier 'inputNew' resolved to null". Fully read the stacktrace. – Tires Jun 18 '14 at 16:02
0

From my little experience in this area. In some cases code:

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

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

produces next error:

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

when I changed the code into code:

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

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

Everithing was OK.

T. Popović
  • 235
  • 2
  • 11