Why is null returned when accessing the managedBean resource?

Asked

Viewed 239 times

1

I’m having problems accessing methods and attributes in a managedbean. I’m using JSF and the Glassfish server, I’ve already used an architecture similar to the one I’m using but on a Tomcat server.

I wonder if anyone has ever had any problem of the type and how did to solve, remembering that for reasons of secrecy, I omitted some attribute names putting Object in place.

Error message:

HTTP Status 500 - Internal Server Error

type Exception report

messageInternal Server Error

descriptionThe server encountered an Internal error that prevented it from fulfilling this request.

Exception

javax.servlet.Servletexception: /index.xhtml @61,185 value="#{controller.object.name}": Target Unreachable, 'null' returned null root cause

javax.el.Propertynotfoundexception: /index.xhtml @61,185 value="#{controller.object.name}": Target Unreachable, 'null' returned null root cause

javax.el.Propertynotfoundexception: Target Unreachable, 'null' returned null note The full stack Traces of the Exception and its root causes are available in the Glassfish Server Open Source Edition 4.1 logs.

Glassfish Server Open Source Edition 4.1

Webpage:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:pt="http://xmlns.jcp.org/jsf/passthrough">

<h:head>
    <meta charset="utf-8"> </meta>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> </meta>
    <meta name="viewport" content="width=device-width, initial-scale=1"> </meta>
    <link rel="icon" href="assets/img/favicon.png"> </link>
    <title>titulo</title>
    <link rel="stylesheet" type="text/css" href="assets/css/reset.css"> </link>
    <link rel="stylesheet" type="text/css" href="assets/css/styles.css"> </link>
    <link rel="stylesheet" type="text/css" href="assets/css/media.css"> </link>

    </h:head>

    <h:body>
        <div id="top">
           <div id="logo">
              <a href="#">
                 <img src="assets/img/logo.png" title=""> </img>
             </a>
         </div>
         <div id="menu">
             <ul>
                <li>
                   <a href="#" id="group-menu">
                    <img src="assets/img/menu-list.png" alt="" title=""> </img>
                   </a>

              </li>
          </ul>
      </div>
  </div>
  <div id="container">
    <div id="second">
        <div id="right">
            <img src="assets/img/background.png"> </img>
        </div>
    </div>
    <div id="first">
        <div id="left">

            <h:form class="cmxform" id="formContato" method="post" action="" onsubmit="updateButtonValue()">

                <h:inputText id="fName" value="#{controller.object.nome}" title="Nome: " tabindex="1" required="true" requiredMessage="O Nome é Obrigatório" pt:placeholder="Nome: "/>

                <h:inputText id="fMail" value="#{controller.object.mail}" title="Email: " tabindex="1" required="true" requiredMessage="O E-mail é Obrigatório" pt:placeholder="E-mail: "/>

                <h:inputText id="fPhone" value="#{controller.object.telefone}" title="Telefone: " tabindex="1" required="true" requiredMessage="O Telefone é Obrigatório" pt:placeholder="Telefone: "/>

                <h:inputText id="fInterest" value="#{controller.object.area}" title="Área de Interesse: " tabindex="1" required="true" requiredMessage="A área de Interesse é Obrigatória" pt:placeholder="Área de Interesse: "/>

                <div id="mensagem">

                </div>

                <h:commandButton value="Salvar" action="#{controller.salvar()}" ></h:commandButton> 


            </h:form>
        </div>
    </div>
</div>
</h:body>

</html>

Controller:

package web.controller;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import application.factory.ApplicationFactory;
import application.interfaces.IContatoApplication;
import business.Contato;

@ManagedBean
@ViewScoped
public class Controller implements Serializable
{
    private static final long serialVersionUID = 1L;

    private Object object = new Object();
    private List<Object> objects = new ArrayList<Object>();

    private IApplication application = ApplicationFactory.getInstance().getApplication();

    public void salvar()
    {   
        Set<String> erros = application.salvar(object);
    }

    public Contato getObject() {
        if(this.object == null)
            this.object = new Object();

        return object;
}

    public void setObject(Object object)
    {
        if(this.object == null)
            this.object = new Object();

        this.object = object;
    }

    public List<Object> getObjects() {
        return objects;
    }

    public void setObjects(List<Object> objects) {
        this.objects = objects;
    }
}
  • The name property exists in the class of your object?

1 answer

0

Anderson I imagine that the 'Object' class created by you has all the desired attributes with its getters and respective setters, remembering that jsf needs the access methods, if yes I ask you to try something...

Declare Private object Object; this way, in managedBean Controller, create the getters and setters standards, without validations as you did above, would look like this..

public Object getObject(){
  return object;
}

public void setObject(Object object){
  this.object = object;
}

now comes the real tip(kkk) use the init method to instantiate your class.

@PostConstruct
public void init(){
    this.object = new Object();
}

I believe this will solve your problem.

  • Hello Doublas, Thanks I managed to solve the problem, I ended up recreating the web project from scratch, it was probably some configuration file that was not created properly

Browser other questions tagged

You are not signed in. Login or sign up in order to post.