tags:

views:

88

answers:

1

Hello i have new Problem with Add Form my problem here

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)

and my back bean

/*
 * 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);
    }


}

Igroup Entity Class

/*
 * 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 + "]";
    }

}

Iuser Entity Class

/*
 * 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 + "]";
    }

}
+1  A: 
value="#{userController.users.username}": 
Target Unreachable, 'null' returned null

Either #{userController} or #{userController.users} is null.

My cents that #{userController.users} is null. You aren't prepopulating it in your bean. The #{userController} is correctly declared and used as @ManagedBean.

You need to prepopulate it in the constructor of the bean:

public UserController() {
    users = new Iuser();
}
BalusC
Hi BalusC i was followed for this way prepopulate users in constructor of userController but when i save it Glassfish server deploy throws NullpointerException ?? it mean users is null? how to solved this problem ? Please help me thank you
Kency
Depends on what exactly is null. Read the stacktrace and fix code accordingly. Either ensure that the reference in question is not null or bypass the access to the reference.
BalusC
yes i was fix my error , my error with getGrouplist method because it now have value from Igroup, that no set for getGrouplist !! One again thank you for your support
Kency
You're welcome.
BalusC