0

I'm trying to build simple JSF app using Glassfish as app server, and it's starting but after that this error is happening:

javax.el.PropertyNotFoundException: /index.xhtml @10,75 value="#{bean.genre}": Target Unreachable, identifier 'bean' 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)....

I tried to change my Bean annotations to @Model and tried different kind of Scopes but that didn't helped.

this is my index.xhtml page:

<!DOCTYPE html>
<html xmlns="http://www.w3c.org/1999/xhtml"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
    <h:form id="genreForm">
        <h:outputLabel for="genre" value="genre" />
        <h:inputText id="genre" value="#{bean.genre}" label="genre" />
        <br/><br/>
        <p:commandButton action="#{bean.addGenre}" update="genreList"
                         value="Add genre" icon="ui-icon-check" style="margin:0"/>
        <br/>
        <br/>
        <h:dataTable  id="genreList" value="#{bean.getGenreList()}" var="g" border="1">
            <h:column>
                <f:facet name="header">
                    Genre id
                </f:facet>
                #{g.genreId}
            </h:column>
            <h:column>
                <f:facet name="header">
                    Name
                </f:facet>
                #{g.genre}
            </h:column>
        </h:dataTable>
    </h:form>
</h:body>

this is my Bean:

@ManagedBean(name = "Bean", eager = true)
@SessionScoped
public class Bean {

private int genreId;
private String genre;

public void addGenre() {
    GenreDAO dao = new GenreDAOImpl();
    Genre myGenre = new Genre();
    myGenre.setGenre(genre);
    dao.save(myGenre);
}

public String getGenre() {
    return genre;
}

public void setGenre(String genre) {
    this.genre = genre;
}

public int getGenreId() {
    return genreId;
}

public void setGenreId(int genreId) {
    this.genreId = genreId;
}

public List<Genre> getGenreList() {
    GenreDAO dao = new GenreDAOImpl();
    List<Genre> list = dao.findAll();
    return list;
}
}
Tiny
  • 24,933
  • 92
  • 299
  • 571
AndreyKle
  • 53
  • 1
  • 6
  • I forget if case is important in EL, but I noticed you used "bean" and "Bean". – markspace Dec 14 '14 at 20:53
  • bean names in JSF EL are definitely case sensitive. How you refer to your bean exactly depends on whether you customized its name in @ManagedBean annotation or not – akhilless Dec 15 '14 at 07:31

2 Answers2

1

By default if you do not provide the managed bean name inside your @ManagedBean annotation the expression language expression used to acess your bean shouldn begin with first letter being in lower case. For example, if you have a following managed bean declaration

@ManagedBean
public class Bean {
    //some fields and methods
}

then you should access your bean with first letter being in lower case

<h:inputText value="#{bean.somePropertyName}">

But you can customize the name used to refer to the bean via @ManagedBean annotation's name attribute. In this case the EL expression you use to refer to your bean should spell the bean's name exactly as provided in your name attribute including the first letter. So if you have this in your code

@ManagedBean (name="Bean")
public class Bean

your bean should be accessed like this

<h:inputText value="#{Bean.somePropertyName}">
akhilless
  • 2,971
  • 16
  • 23
0
@ManagedBean(name = "Bean", eager = true)

Here you are setting the bean's name as "Bean" but you are trying to access it as "bean" in your el. Change either of them ot get it working.

Salih Erikci
  • 4,868
  • 9
  • 34
  • 65