Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1092731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:43:37+00:00 2026-05-16T23:43:37+00:00

Hello Everybody now i working with JSF 2.0 and EJB3 and i used Primefaces

  • 0

Hello Everybody now i working with JSF 2.0 and EJB3 and i used Primefaces to display error message or success message, i have two problem are
one when i put Button sumit (JSF command button) next page Error display

/register.xhtml @26,172 value=”#{userController.user.username}”: Target Unreachable, ‘null’ returned null

my code are

User Entity

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

package com.demoejb.entity;

import java.io.Serializable;
import java.util.Date;
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.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
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 = "group", referencedColumnName = "g_id")
    @ManyToOne(optional = false)
    private Igroup igroup;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "iuser")
    private List<Irent> irentList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "iuser")
    private List<Ipayment> ipaymentList;

    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 List<Irent> getIrentList() {
        return irentList;
    }

    public void setIrentList(List<Irent> irentList) {
        this.irentList = irentList;
    }

    public List<Ipayment> getIpaymentList() {
        return ipaymentList;
    }

    public void setIpaymentList(List<Ipayment> ipaymentList) {
        this.ipaymentList = ipaymentList;
    }

    @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.demoejb.entity.Iuser[uid=" + uid + "]";
    }

}

Session Bean class

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

package com.demoejb.DAO;

import com.demoejb.entity.Igroup;
import com.demoejb.entity.Iuser;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author KencyWindy
 */
@Stateless
@LocalBean
public class UserSessionBean {
    @PersistenceContext(unitName = "DemoEJB3-ejbPU")
    private EntityManager em;

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")



    public void persist(Object object) {
        em.persist(object);
    }

   public Object persistEntity(Object entity) {
         em.persist(entity);
         return entity;
    }

   public Object updateEntity(Object entity){
    return em.merge(entity);
   }

   public void removeUser(Iuser user){
    user = em.find(Iuser.class, user.getUid());
   }

   public List<Iuser> getAllUser(){
    return em.createNamedQuery("Iuser.findAll").getResultList();
   }

   /*Check username and email if new user enter into form
    * if exist throw exception, this feature will be used in controller
    */
   public Iuser checkExistUser(String email,String username){
        Iuser entity = null;
       try {
            javax.persistence.Query query = em.createQuery("select u from iuser u where iuser.email = : email or iuser.username = :username");
            query.setParameter("email", email);
            query.setParameter("username", username);
            entity = (Iuser) query.getResultList();
       } catch (Exception e) {
       }
        return entity;
   }

   public Iuser addUser(Iuser user){

        persist(user);
       return  user;
   }

    public void persist1(Object object) {
        em.persist(object);
    }
    /*
     * Get all group in database
     */
    public List<Igroup> getGroup() {

        return em.createNamedQuery("Igroup.findAll").getResultList();
    }


}

JSF Managed Bean class

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

package com.demo.controller;

import com.demoejb.DAO.UserSessionBean;
import com.demoejb.entity.Igroup;
import com.demoejb.entity.Iuser;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;


/**
 *
 * @author KencyWindy
 */
public class UserController {
    @EJB
    private UserSessionBean userSessionBean;
    private Iuser user;






    /** Creates a new instance of UserController */
    public UserController() {
    }

    public Iuser getUser() {
        return user;
    }

    public void setUser(Iuser user) {
        this.user = user;
    }

     public String addUser(){
        String toReturn =  "false";
        String email = user.getEmail();
        String username = user.getUsername();
        try {
                if(userSessionBean.checkExistUser(email, username) != null){
                    FacesContext context = FacesContext.getCurrentInstance();
                     context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
                    "Error", "username or email id has been exist!"));
                    toReturn = "False";
                }
                 else   {
                 Igroup g = new Igroup();
                 Date date = new Date();
                 java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                 String getDate = sdf.format(date);
                 Date regDate = sdf.parse(getDate);
                 user.setRegdate(regDate);
                 user.setLastlogin(regDate);
                 g.setGId(1);
                 user.setIgroup(g);
                 user = userSessionBean.addUser(user);
                 FacesContext context = FacesContext.getCurrentInstance();
                context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
                    "Sucessful", "New user has been created!"));

             }
        } catch (Exception e) {
        }

        return toReturn;
    }

    /*
     * Create list group for user can choose to edit
     * warning !!!! this feature it can posible for administrator
     */

     public javax.faces.model.SelectItem[] getGrouplist(){
        SelectItem[] options = null;
        List<Igroup> lGroups = userSessionBean.getGroup();
        if(lGroups != null && lGroups.size() > 0){
            int i = 0 ;
            options = new SelectItem[lGroups.size()];
            for (Igroup iGroup : lGroups){
                options[i++] = new SelectItem(iGroup.getGId(), iGroup.getGName());
            }
        }
        return options;
     }


}

Face- config

<?xml version='1.0' encoding='UTF-8'?>

<!-- =========== FULL CONFIGURATION FILE ================================== -->

<faces-config version="2.0"
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
    <managed-bean>
        <description>Controller for enntire User module</description>
        <managed-bean-name>userController</managed-bean-name>
        <managed-bean-class>com.demo.controller.UserController</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
</faces-config>

Second problem is i not give group table into combobox with h:selectOne

<h:outputLabel value="Igroup:" for="igroup" />
                    <h:selectOneMenu id="igroup" value="#{userController.user.igroup}" title="Igroup" required="true" requiredMessage="The Igroup field is required.">
                        <!-- TODO: update below reference to list of available items-->
                        <f:selectItems value="#{userController.grouplist}"/>
                    </h:selectOneMenu>

When i used error occured, i dont know why occur error? i write getGrouplist from JSFManageBean and have 1 method getAllGroup Current of table in database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:43:38+00:00Added an answer on May 16, 2026 at 11:43 pm

    Hey, I just ran into a very similar problem and stumbled upon this from Google. I fixed it by creating an empty data object in the ManagedBean that you’re mapping it to, in your case that would be correcting

    “private Iuser user;”

    to

    “private Iuser user = new Iuser();”

    in the UserController class.

    As I’m pretty new to EE myself, I can’t really explain why, but it helped me & hope it solves your problem too…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello everybody i have a listbox within which is a datatemplate.Inside it is checkbox,textbox,label...Wat
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello everybody I have this string: [JOLLY BLU at STAY SHIP, Voy: 0275/11] How
Hello everybody I have a question: I have a array String[] parte and I
Hello everybody! I have a SQL (see above) and i would like to know
Hello everybody let me give you the background first: I'm working on a project
Note: Using Monotouch and doing all the UI Programatically. Hello everybody, I have a
Suppose I have String str=Hello $everybody$. How $are$ you $all$; From above string, I
Everybody, Hello! This is my request message: <soap:Envelope xmlns:soap=http://schemas.xmlsoap.org/soap/envelope/> <soap:Header> <wsse:Security xmlns:wsse=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd xmlns:wsu=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd soap:mustUnderstand=1>
Everybody, Hello! I have a simple stub client for the cxf web-service (spring app).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.