web-dev-qa-db-fra.com

PropertyNotFoundException: cible inaccessible, 'null' a renvoyé la valeur null

Bonjour, j’ai un nouveau problème avec Add Form Mon problème ici 

WARNING: /test.xhtml @24,173 value="#{userController.users.username}": Target Unreachable, 'null' returned null
javax.el.PropertyNotFoundException: /test.xhtml @24,173 value="#{userController.users.username}": Target Unreachable, 'null' returned null
        at com.Sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.Java:93)
        at com.Sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.Java:95)
        at javax.faces.component.UIInput.getConvertedValue(UIInput.Java:1008)
        at javax.faces.component.UIInput.validate(UIInput.Java:934)
        at javax.faces.component.UIInput.executeValidate(UIInput.Java:1189)
        at javax.faces.component.UIInput.processValidators(UIInput.Java:691)
        at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.Java:1080)
        at javax.faces.component.UIForm.processValidators(UIForm.Java:243)
        at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.Java:1080)
        at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.Java:1080)
        at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.Java:1180)
        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:118)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.Java:312)
        at org.Apache.catalina.core.StandardWrapper.service(StandardWrapper.Java:1523)
        at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:279)
        at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:188)
        at org.Apache.catalina.core.StandardPipeline.invoke(StandardPipeline.Java:641)
        at com.Sun.enterprise.web.WebPipeline.invoke(WebPipeline.Java:97)
        at com.Sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.Java:85)
        at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:185)
        at org.Apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.Java:325)
        at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:226)
        at com.Sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.Java:165)
        at com.Sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.Java:791)
        at com.Sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.Java:693)
        at com.Sun.grizzly.http.ProcessorTask.process(ProcessorTask.Java:954)
        at com.Sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.Java:170)
        at com.Sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.Java:135)
        at com.Sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.Java:102)
        at com.Sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.Java:88)
        at com.Sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.Java:76)
        at com.Sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.Java:53)
        at com.Sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.Java:57)
        at com.Sun.grizzly.ContextTask.run(ContextTask.Java:69)
        at com.Sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.Java:330)
        at com.Sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.Java:309)
        at Java.lang.Thread.run(Thread.Java:619)

et mon haricot arrière

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ejb.controller;

import com.ejbbean.iUserBean;
import com.entity.Igroup;
import com.entity.Iuser;
import Java.awt.event.ActionEvent;
import Java.io.Serializable;
import Java.util.List;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;

import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;

/**
 *
 * @author KencyWindy
 */
@ManagedBean
@ViewScoped
public class UserController implements Serializable{
    @EJB
    private iUserBean iUserBean;
    private Iuser users  ;
    private Igroup groupa;



    public UserController() {

    }
     public Igroup getGroupa() {
        return groupa;
    }

    public void setGroupa(Igroup groupa) {
        this.groupa = groupa;
    }

    public Iuser getUsers() {
        return users;
    }

    public void setUsers(Iuser users) {
        this.users = users;
    }


    public List<Iuser> getAllUser(){
        return iUserBean.retrieve();
    }


    public void addUser(){


        users = new Iuser();
        users = iUserBean.createUser(users);



    }
     public javax.faces.model.SelectItem[] getAllOfGroups(){
        SelectItem[] options = null;

        List<Igroup> lgroup = iUserBean.retrieveGroup();
        if(lgroup.size() > 0 && lgroup != null){
            options = new SelectItem[lgroup.size()];
            int i = 0 ;
            for ( Igroup igroup : lgroup){
                options[i++] = new SelectItem(igroup.getGId(), igroup.getGroupname());
            }
        }

        return options;

    }




     public void submit(ActionEvent event) {
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Correct", "Correct");

        FacesContext.getCurrentInstance().addMessage(null, msg);
    }


}

Classe d'entité Igroup

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.entity;

import Java.io.Serializable;
import Java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author KencyWindy
 */
@Entity
@Table(name = "igroup")
@NamedQueries({
    @NamedQuery(name = "Igroup.findAll", query = "SELECT i FROM Igroup i"),
    @NamedQuery(name = "Igroup.findByGId", query = "SELECT i FROM Igroup i WHERE i.gId = :gId"),
    @NamedQuery(name = "Igroup.findByGroupname", query = "SELECT i FROM Igroup i WHERE i.Groupname = :Groupname"),
    @NamedQuery(name = "Igroup.findByAdministrator", query = "SELECT i FROM Igroup i WHERE i.administrator = :administrator"),
    @NamedQuery(name = "Igroup.findByReaded", query = "SELECT i FROM Igroup i WHERE i.readed = :readed"),
    @NamedQuery(name = "Igroup.findByDeleted", query = "SELECT i FROM Igroup i WHERE i.deleted = :deleted"),
    @NamedQuery(name = "Igroup.findByUpdated", query = "SELECT i FROM Igroup i WHERE i.updated = :updated"),
    @NamedQuery(name = "Igroup.findByModed", query = "SELECT i FROM Igroup i WHERE i.moded = :moded"),
    @NamedQuery(name = "Igroup.findByAdded", query = "SELECT i FROM Igroup i WHERE i.added = :added")})
public class Igroup implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "g_id")
    private Integer gId;
    @Basic(optional = false)
    @Column(name = "g_name")
    private String Groupname;
    @Column(name = "administrator")
    private Boolean administrator;
    @Basic(optional = false)
    @Column(name = "readed")
    private boolean readed;
    @Column(name = "deleted")
    private Boolean deleted;
    @Column(name = "updated")
    private Boolean updated;
    @Column(name = "moded")
    private Boolean moded;
    @Column(name = "added")
    private Boolean added;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "igroup")
    private List<Iuser> iuserList;

    public Igroup() {
    }

    public Igroup(Integer gId) {
        this.gId = gId;
    }

    public Igroup(Integer gId, String gName, boolean readed) {
        this.gId = gId;
        this.Groupname = gName;
        this.readed = readed;
    }

    public Integer getGId() {
        return gId;
    }

    public void setGId(Integer gId) {
        this.gId = gId;
    }

    public String getGroupname() {
        return Groupname;
    }

    public void setGroupname(String Groupname) {
        this.Groupname = Groupname;
    }

    public Boolean getAdministrator() {
        return administrator;
    }

    public void setAdministrator(Boolean administrator) {
        this.administrator = administrator;
    }

    public boolean getReaded() {
        return readed;
    }

    public void setReaded(boolean readed) {
        this.readed = readed;
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    public Boolean getUpdated() {
        return updated;
    }

    public void setUpdated(Boolean updated) {
        this.updated = updated;
    }

    public Boolean getModed() {
        return moded;
    }

    public void setModed(Boolean moded) {
        this.moded = moded;
    }

    public Boolean getAdded() {
        return added;
    }

    public void setAdded(Boolean added) {
        this.added = added;
    }

    public List<Iuser> getIuserList() {
        return iuserList;
    }

    public void setIuserList(List<Iuser> iuserList) {
        this.iuserList = iuserList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (gId != null ? gId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Igroup)) {
            return false;
        }
        Igroup other = (Igroup) object;
        if ((this.gId == null && other.gId != null) || (this.gId != null && !this.gId.equals(other.gId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.entity.Igroup[gId=" + gId + "]";
    }

}

Classe d'entité Iuser 

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.entity;

import Java.io.Serializable;
import Java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author KencyWindy
 */
@Entity
@Table(name = "iuser")
@NamedQueries({
    @NamedQuery(name = "Iuser.findAll", query = "SELECT i FROM Iuser i"),
    @NamedQuery(name = "Iuser.findByUid", query = "SELECT i FROM Iuser i WHERE i.uid = :uid"),
    @NamedQuery(name = "Iuser.findByUsername", query = "SELECT i FROM Iuser i WHERE i.username = :username"),
    @NamedQuery(name = "Iuser.findByPassword", query = "SELECT i FROM Iuser i WHERE i.password = :password"),
    @NamedQuery(name = "Iuser.findByPnum", query = "SELECT i FROM Iuser i WHERE i.pnum = :pnum"),
    @NamedQuery(name = "Iuser.findByZipcode", query = "SELECT i FROM Iuser i WHERE i.zipcode = :zipcode"),
    @NamedQuery(name = "Iuser.findByState", query = "SELECT i FROM Iuser i WHERE i.state = :state"),
    @NamedQuery(name = "Iuser.findByDob", query = "SELECT i FROM Iuser i WHERE i.dob = :dob"),
    @NamedQuery(name = "Iuser.findByEmail", query = "SELECT i FROM Iuser i WHERE i.email = :email"),
    @NamedQuery(name = "Iuser.findByLastlogin", query = "SELECT i FROM Iuser i WHERE i.lastlogin = :lastlogin"),
    @NamedQuery(name = "Iuser.findByRegdate", query = "SELECT i FROM Iuser i WHERE i.regdate = :regdate"),
    @NamedQuery(name = "Iuser.findByAddress", query = "SELECT i FROM Iuser i WHERE i.address = :address"),
    @NamedQuery(name = "Iuser.findByCity", query = "SELECT i FROM Iuser i WHERE i.city = :city")})
public class Iuser implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "uid")
    private Integer uid;
    @Basic(optional = false)
    @Column(name = "username")
    private String username;
    @Basic(optional = false)
    @Column(name = "password")
    private String password;
    @Basic(optional = false)
    @Column(name = "pnum")
    private int pnum;
    @Basic(optional = false)
    @Column(name = "zipcode")
    private int zipcode;
    @Basic(optional = false)
    @Column(name = "state")
    private String state;
    @Basic(optional = false)
    @Column(name = "dob")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dob;
    @Basic(optional = false)
    @Column(name = "email")
    private String email;
    @Column(name = "lastlogin")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastlogin;
    @Column(name = "regdate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date regdate;
    @Basic(optional = false)
    @Column(name = "address")
    private String address;
    @Basic(optional = false)
    @Column(name = "city")
    private String city;
    @JoinColumn(name = "igroup", referencedColumnName = "g_id")
    @ManyToOne(optional = false)
    private Igroup igroup;

    public Iuser() {
    }

    public Iuser(Integer uid) {
        this.uid = uid;
    }

    public Iuser(Integer uid, String username, String password, int pnum, int zipcode, String state, Date dob, String email, String address, String city) {
        this.uid = uid;
        this.username = username;
        this.password = password;
        this.pnum = pnum;
        this.zipcode = zipcode;
        this.state = state;
        this.dob = dob;
        this.email = email;
        this.address = address;
        this.city = city;
    }

    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getPnum() {
        return pnum;
    }

    public void setPnum(int pnum) {
        this.pnum = pnum;
    }

    public int getZipcode() {
        return zipcode;
    }

    public void setZipcode(int zipcode) {
        this.zipcode = zipcode;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public Date getDob() {
        return dob;
    }

    public void setDob(Date dob) {
        this.dob = dob;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getLastlogin() {
        return lastlogin;
    }

    public void setLastlogin(Date lastlogin) {
        this.lastlogin = lastlogin;
    }

    public Date getRegdate() {
        return regdate;
    }

    public void setRegdate(Date regdate) {
        this.regdate = regdate;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public Igroup getIgroup() {
        return igroup;
    }

    public void setIgroup(Igroup igroup) {
        this.igroup = igroup;
    }


    public Integer getGrouplist(){
        return this.igroup.getGId();
    }

    public void setGrouplist(Integer intgroup){
        this.igroup = new Igroup(intgroup);

    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (uid != null ? uid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Iuser)) {
            return false;
        }
        Iuser other = (Iuser) object;
        if ((this.uid == null && other.uid != null) || (this.uid != null && !this.uid.equals(other.uid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.entity.Iuser[uid=" + uid + "]";
    }

}
13
Kency
value="#{userController.users.username}": 
Target Unreachable, 'null' returned null

#{userController} ou #{userController.users} est null.

Mes cents que #{userController.users} est null. Vous ne pré-remplissez pas dans votre haricot. Le #{userController} est correctement déclaré et utilisé en tant que @ManagedBean.

Vous devez le pré-remplir dans la post-structure du haricot:

@PostConstruct
public void init() {
    users = new Iuser();
}
25
BalusC

Dans la classe UserController, déclarez votre variable comme ceci.

public Iuser users = new Iuser();

Parce que sauf si vous utilisez new Iuser(), l'objet n'est pas créé et il retournera une valeur null.

2
pmverma

initialiser votre classe Iuser dans le haricot de sauvegarde comme ceci

public Iuser getUsers() {
if(users == null){
users = (Iuser )super.getInstance(Iuser.Class);
}
return users;
}

cela créera un nouvel objet Iuser si l'objet devient nul

0
user3143408