Forum Stats

  • 3,854,528 Users
  • 2,264,379 Discussions
  • 7,905,718 Comments

Discussions

Why does Glassfish failed to rendered xhtml?

2707803
2707803 Member Posts: 3
edited Apr 3, 2015 3:38AM in New To Java

Hello java.net i'm very new to javaweb and i tried to create my first javaweb project, off course by following some tutorial. however when some action were being connected i received an error. Here are what i did:

First  i have my model Friend

@Named

@RequestScoped

@Entity

@Table(name = "FRIEND")

@XmlRootElement

@NamedQueries({

    @NamedQuery(name = "Friend.findAll", query = "SELECT f FROM Friend f"),

         .......})

public class Friend implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id

    @Basic(optional = false)

    @NotNull

    @Column(name = "FRIEND_ID")

    private Integer friendId;

    @Size(max = 30)

    @Column(name = "LAST_NAME")

    private String lastName;

    @Size(max = 30)

    @Column(name = "FIRST_NAME")

    private String firstName;

    .

    .

    .

Second I created FriendEJBDao

@Stateless

public class FriendEJBDao {

   

@PersistenceContext

    EntityManager em;

    @Inject Friend f;

    public List<Friend> getFriend(){

        return em.createNamedQuery("Friend.findAll").getResultList();

    }

   

    public void create(){

        Friend friend = new Friend(f.getLastName(),f.getFirstName(),f.getMiddleName(),f.getAge());

em.persist(friend);

    }

   .

   .

   .

Third I created FriendBean

@Named(value = "friendBean")

@RequestScoped

public class FriendBean {

    private List<Friend> friend;

    @Inject

    FriendEJBDao friendEjbDao;

    public FriendBean() {

    }

   

    public List<Friend> getFriends(){

        if(friend == null){

            friend = friendEjbDao.getFriend();

        }

        return friend;

    }

   

    public void create(){

friendEjbDao.create();

    }

}

Fourth I create an xhtml file named list

.

.

.

<ui:composition template="./WEB-INF/template.xhtml">

<ui:define name="content">

<h:form>

<h:dataTable value="#{friendBean.friends}" var="friend">

<h:column>

<f:facet name="header">Full Name</f:facet>

#{friend.lastName}, #{friend.middleName} #{friend.middleName}

</h:column>

<h:column>

<f:facet name="header">Age</f:facet>

#{friend.age}

</h:column>

</h:dataTable>

                   

<h:commandButton action="create" value="Create"/>

</h:form>

</ui:define>

</ui:composition>

.

.

.

5th i created an xhtml file named create

.

.

.

<ui:composition template="./WEB-INF/template.xhtml">

<ui:define name="content">

<h:form>

<h:panelGrid columns="3"

captionClass="rightalign,leftalign,leftalign">

<h:outputLabel value="Last Name:" for="lastName"/>

<h:inputText id="lastName" label="Last Name"

                                         required="true"

value="#{friend.lastName}"/>

<h:message for="lastName"/>

<h:outputLabel value="First Name:" for="firstName"/>

<h:inputText id="firstName" label="First Name"

required="true"

value="#{friend.firstName}"/>

<h:message for="firstName"/>

<h:outputLabel value="Middle Name:" for="middleName"/>

<h:inputText id="middleName" label="Middle Name"

required="true"

                                         value="#{friend.middleName}"/>

<h:message for="middleName"/>

<h:outputLabel value="Age:" for="age"/>

<h:inputText id="age" label="Age"

                                         size="2"

value="#{friend.age}"/>

<h:message for="age"/>

<h:panelGroup/>

<h:commandButton id="save" value="Save"

                                             action="list" actionListener="#{friendBean.create}"/>

</h:panelGrid>

</h:form>

</ui:define>

</ui:composition>

.

.

.

When tried to run my project what happened were:

  1. No data was displayed in list.xhtml (before i created create.xhtml, it displayed the list of friend)
  2. When i clicked 'Save' button in create.xhtml  here is the error i received:

An Error Occurred:

/create.xhtml @18,70 value="#{friend.lastName}": Target Unreachable, identifier 'friend' resolved to null

I expand Stack Trace and it displayed

  1. javax.el.PropertyNotFoundException: /create.xhtml @18,70 value="#{friend.lastName}": Target Unreachable, identifier 'friend' resolved to null

.

.

.

Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'friend' 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 com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)

                ... 41 more

Hope this can be published and someone can help me to resolve this problem.

Tagged:
This discussion has been closed.