Announcement Announcement Module
Collapse
No announcement yet.
'id' in bean of type null Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 'id' in bean of type null

    Hello every body,

    I am trying for last one day to resolve the following problem. I will be very grateful if some one help me. I am using jsf,service layer, businesslayer,data access object layer


    *************login.jsp**********

    <html>
    <head>
    <title>enter your name page</title>
    </head>
    <body>
    <f:view>
    <h1>
    <h:outputText value="Welcome Welcome"/>
    </h1>
    <h:form id="helloForm">
    <h:outputText value="User ID:"/>
    <h:inputText id="userid" value="#{user.userBean.id}" />
    <h:outputText value="User Name:"/>
    <h:inputText id="userName" value="#{user.userBean.userName}" />
    <h:outputText value="Password:"/>
    <h:inputText id="userPassword" value="#{user.userBean.userPassword}" />
    <h:commandButton id="save" action="#{userBean.save}" value="Save" />
    </h:form>
    </f:view>
    </body>
    </html>

    ***************UserBean.java************
    package view.bean.user;

    import model.businessobject.User;
    import model.service.UserService;

    public class UserBean {

    private User user=new User();
    private UserService userService;
    long id;
    String userName;
    String userPassword;

    public String sava(){
    userService.saveUser(user);
    return "success";
    }
    public User getUser() {
    return user;
    }
    public void setUser(User user) {
    this.user = user;
    }
    public UserService getUserService() {
    return userService;
    }
    public void setUserService(UserService userService) {
    this.userService = userService;
    }
    public long getId() {
    return id;
    }
    public void setId(long id) {
    this.id =id;
    }
    public String getUserName() {
    return userName;
    }
    public void setUserName(String userName) {
    this.userName = userName;
    }
    public String getUserPassword() {
    return userPassword;
    }
    public void setUserPassword(String userPassword) {
    this.userPassword = userPassword;
    }
    }

    **************faces-config.xml*************

    <faces-config>

    <application>
    <variable-resolver>
    org.springframework.web.jsf.DelegatingVariableReso lver
    </variable-resolver>
    </application>

    <navigation-rule>
    <from-view-id>/login.jsp</from-view-id>
    <navigation-case>
    <from-outcome>success</from-outcome>
    <to-view-id>/successLogin.jsp</to-view-id>
    </navigation-case>
    </navigation-rule>
    <managed-bean>
    <managed-bean-name>userBean</managed-bean-name>
    <managed-bean-class>view.bean.user.UserBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

    </faces-config>

    **************applicationContext.xml************

    <beans>
    <!-- DataSource Definition -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbcostgresql://127.0.0.1:5432/db"/>
    <property name="username" value="aa"/>
    <property name="password" value="bb"/>
    </bean>

    <!-- Hibernate SessionFactory Definition -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <!-- <property name="dataSource" ref="myDataSource"/>-->
    <property name="mappingResources">
    <list>
    <value>model/businessobject/User.hbm.xml</value>
    </list>
    </property>

    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.Post greSQLDialect</prop>
    </props>
    </property>

    <property name="dataSource">
    <ref bean="dataSource"/>
    </property>
    </bean>

    <!-- Hibernate Template Definition -->
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.Hibernat eTemplate">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>

    <!-- User Dao Definition: Hibernate implementation -->
    <bean id="userDao" class="model.dao.hibernate.UserDaoHibernateImpl">
    <property name="hibernateTemplate">
    <ref bean="hibernateTemplate"/>
    </property>
    </bean>

    <!-- Start of Service Definitions -->

    <!-- Hibernate Transaction Manager Definition -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory">
    <ref local="sessionFactory"/>
    </property>
    </bean>

    <!-- User Service Definition -->
    <bean id="userServiceTarget" class="model.service.impl.UserServiceImpl">
    <property name="userDao">
    <ref local="userDao"/>
    </property>
    </bean>

    <bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.Hibernat eInterceptor">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>

    <!-- Transactional proxy for the Service classes -->
    <bean id="userService" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref local="transactionManager"/>
    </property>
    <property name="target">
    <ref local="userServiceTarget"/>
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>
    </beans>

    ***************web.xml***************

    <listener>
    <listener-class>
    org.springframework.web.context.ContextLoaderListe ner
    </listener-class>
    </listener>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
    </context-param>

    <context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/faces-config.xml</param-value>
    </context-param>

    <listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>

    <!-- Faces Servlet -->
    <servlet>
    <servlet-name>javax.faces.FacesServlet</servlet-name>
    <!-- <servlet-name>Faces Servlet</servlet-name>-->
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup> 1 </load-on-startup>
    </servlet>

    <!-- Faces Servlet Mapping -->
    <servlet-mapping>
    <servlet-name>javax.faces.FacesServlet</servlet-name>
    <!-- <servlet-name>Faces Servlet</servlet-name>-->
    <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>

    </web-app>

    *****************User.java************
    package model.businessobject;

    public class User {
    public long id;
    public String userName;
    public String userPassword;

    public long getId() {
    return id;
    }
    public void setId(long id) {
    this.id = id;
    }
    public String getUserPassword() {
    return userPassword;
    }
    public void setUserPassword(String userPassword) {
    this.userPassword = userPassword;
    }
    public String getUserName() {
    return userName;
    }
    public void setUserName(String userName) {
    this.userName = userName;
    }
    }
    *****************User.hbm.xml**************
    <!--<?xml version="1.0"?>-->
    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping>
    <class name="model.businessobject.User" table="USER">
    <id name="id" type="long" column="ID" >
    <generator class="assigned"/>
    </id>

    <property name="userName">
    <column name="USERNAME" />
    </property>
    <property name="userPassword">
    <column name="USERPASSWORD"/>
    </property>
    </class>
    </hibernate-mapping>
    ****************UserService.java***********
    package model.service;

    import model.businessobject.User;

    public interface UserService {
    public void saveUser(User user);
    }
    *************UserServiceImpl.java********
    package model.service.impl;

    import model.businessobject.User;
    import model.dao.UserDao;
    import model.service.UserService;

    public class UserServiceImpl implements UserService {
    private UserDao userDao;
    public void saveUser(User user){
    userDao.save(user);
    }
    public UserDao getUserDao(){
    return userDao;
    }
    public void setUserDao(UserDao userDao)
    {
    this.userDao=userDao;
    }
    }
    *************UserDao.java**********
    package model.dao;

    import model.businessobject.User;

    public interface UserDao {
    public void save(User user);
    }
    ***************UserDaoHibernateImpl.java**********
    package model.dao.hibernate;
    import org.springframework.orm.hibernate3.support.Hiberna teDaoSupport;

    import model.businessobject.User;
    import model.dao.*;

    public class UserDaoHibernateImpl extends HibernateDaoSupport implements UserDao{

    public void save(User user) {
    getHibernateTemplate().save(user);

    }
    }

    *******
    Error is
    *******
    javax.servlet.ServletException: Error testing property 'id' in bean of type null
    javax.faces.webapp.FacesServlet.service(FacesServl et.java:209)
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(ReplyHeaderFilter.java:81)
    root cause
    javax.faces.el.PropertyNotFoundException: Error testing property 'id' in bean of type null
Working...
X