0

I'm playing around with CDI in Java EE, but it doesn't seem to work.

I have a very simple example with 2 text fields. When entering the name and submit, the entered name should appear on the next page.

enter image description here

But instead I get the following error:

HTTP Status 500 - Internal Server Error

javax.servlet.ServletException: /index.xhtml @12,72 value="#{userBean.firstName}": Target Unreachable, identifier 'userBean' resolved to null

javax.el.PropertyNotFoundException: /index.xhtml @12,72 value="#{userBean.firstName}": Target Unreachable, identifier 'userBean' resolved to null

javax.el.PropertyNotFoundException: Target Unreachable, identifier 'userBean' resolved to null

These are my 3 files:

index.xhtml

<h:form>
    <h:panelGrid columns="2">
        <h:outputLabel value="First name" for="firstName"/>
        <h:inputText id="firstName" value="#{userBean.firstName}"/>


        <h:outputLabel value="Last name" for="lastName"/>
        <h:inputText id="lastName" value="#{userBean.lastName}"/>
      <h:commandButton action="result" value="send"/>
    </h:panelGrid>
</h:form>

result.xhtml

First name: #{userBean.firstName}
Last name: #{userBean.lastName}

UserBean.java

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

@Named
@RequestScoped
public class UserBean {

    private String firstName;
    private String lastName;

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

}
Evgenij Reznik
  • 16,046
  • 33
  • 87
  • 157
  • The `index.xhtml` has the markup ``. What is the `action` attribute referring to? What is the expected outcome (is it the `result` page)? – prasad_ Dec 28 '18 at 03:33
  • Here is a link to the Java EE tutorial topic [Navigation model](https://docs.oracle.com/javaee/7/tutorial/jsf-intro005.htm). Refer to what is _Implicit Navigation_. – prasad_ Dec 28 '18 at 03:49
  • I tried the similar code on Glassfish 4 (Java EE 7) with same annotations (CDI) and code. I am running Java 8. The web app works fine, there was no error. The only issue with your code - I have already mentioned in my previous comments, but that doesn't produce any errors. You can also try searching the net (Google) with a search string like _"JSF Target Unreachable, identifier bean resolved to null"_ and find some answers. – prasad_ Dec 28 '18 at 05:05
  • You **SHOULD** also try searching the net (...) with a search string like a_"JSF Target Unreachable, identifier bean resolved to null"_ and find some answers. – Kukeltje Dec 28 '18 at 07:32
  • @prasad_: I already had a look at [this link](https://stackoverflow.com/questions/30128395/identifying-and-solving-javax-el-propertynotfoundexception-target-unreachable), but it didn't solve my problem. One important difference could be: I'm using Linux. – Evgenij Reznik Dec 29 '18 at 00:06
  • You may edit and post the complete code of your XHTML, including the configuration files like `web.xml` and `faces-config.xml`. And, how you have deployed (the folder structure and the files in it). I don't know if OS can make a difference. Also, you may want to mention the versions of various software you are using in this application - like Java SE, Glassfish, etc. Make sure you don't have different versions of you source code... – prasad_ Dec 29 '18 at 06:51

0 Answers0