Announcement Announcement Module
Collapse
No announcement yet.
Null Poineter Exception in Validator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Null Poineter Exception in Validator

    Hi,

    Hopefully this is just a simple config goof and not a manifestation of a nightmare. :-)

    Our app is a simple web app with a form backing object called "survey" and a helper object "surveyService". All the DAO's etc. are wired into the surveyService.

    I'm trying to validate whether a string provided on the form is legit. For simple checks, no problem. However for one test I need to query one DB table to get a userId from the string provided, then query a second table with the userId to do the validation. "This should be easy" thinks I. "All the methods already exist in surveyService."

    Except that I get a null pointer exception in the validator. "surveyservice" is null.

    Yes, I have surveyService decalred in the validator, and have a setter too. The relevant parts of the ApplicationContext.xml are below.

    What obvious thing did I overlook? ... or (perish the thought) does the validator exist in some no-man's land of life-cycle of the from backing object helpers?

    =====================
    <bean name="surveyServiceTarget"
    class="com.once.client.gro.sweeps0010.SurveyServic e">
    <property name="sweepContentDao"><ref bean="sweepContentDao"/></property>
    <property name="ageGroupDao"><ref bean="ageGroupDao"/></property>
    <property name="childGetDao"><ref bean="childGetDao"/></property>
    <property name="childPutDao"><ref bean="childPutDao"/></property>
    <property name="optInDao"><ref bean="optInDao"/></property>
    <property name="dataTafDao"><ref bean="dataTafDao"/></property>
    <property name="bvDao"><ref bean="bvDao"/></property>
    <property name="templatedEmailService"><ref bean="templatedEmailService"/></property>
    <property name="formResponsesDao"><ref bean="formResponsesDao"/></property>
    <property name="sweepUserDao"><ref bean="sweepUserDao"/></property>
    </bean>

    <bean name="surveyService"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="target"><ref bean="surveyServiceTarget"/></property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED,-java.lang.Exception</prop>
    </props>
    </property>
    </bean>

    <bean name="sweepValidatorTarget"
    class="com.once.client.gro.sweeps0010.ui.SweepVali dator">
    <property name="surveyService"><ref bean="surveyService"/></property>
    </bean>

    <bean name="sweepValidator"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="target"><ref bean="sweepValidatorTarget"/></property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED,-java.lang.Exception</prop>
    </props>
    </property>
    </bean>
    --
    Richard Johnson

  • #2
    maybe you miss transactionManager config.

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
       "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    	
    	<bean name="surveyServiceTarget"
    		class="com.once.client.gro.sweeps0010.SurveyService">
    		
    		<!--		<property name="sweepContentDao"><ref bean="sweepContentDao"/></property>
    		<property name="ageGroupDao"><ref bean="ageGroupDao"/></property>
    		<property name="childGetDao"><ref bean="childGetDao"/></property>
    		<property name="childPutDao"><ref bean="childPutDao"/></property>
    		<property name="optInDao"><ref bean="optInDao"/></property>
    		<property name="dataTafDao"><ref bean="dataTafDao"/></property>
    		<property name="bvDao"><ref bean="bvDao"/></property>
    		<property name="templatedEmailService"><ref bean="templatedEmailService"/>
    		</property>
    		<property name="formResponsesDao"><ref bean="formResponsesDao"/>
    		</property>
    		<property name="sweepUserDao"><ref bean="sweepUserDao"/></property>-->
    		
    	</bean>
    	
    	<bean name="surveyService"
    		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager">
    			<ref bean="transactionManager"/>
    		</property>
    		<property name="target">
    			<ref bean="surveyServiceTarget"/></property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="*">PROPAGATION_REQUIRED,-java.lang.Exception</prop>
    			</props>
    		</property>
    	</bean>
    	
    	<bean name="sweepValidatorTarget"
    		class="com.once.client.gro.sweeps0010.ui.SweepValidator">
    		<property name="surveyService">
    			<ref bean="surveyService"/>
    		</property>
    	</bean>
    	
    	<bean name="sweepValidator"
    		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager"><ref bean="transactionManager"/>
    		</property>
    		<property name="target"><ref bean="sweepValidatorTarget"/></property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="*">PROPAGATION_REQUIRED,-java.lang.Exception</prop>
    			</props>
    		</property>
    	</bean>
    	
    	<bean id="transactionManager"
    		class="org.springframework.orm.hibernate.HibernateTransactionManager">
    		<property name="sessionFactory">
    			<ref local="sessionFactory"/>
    		</property>
    	</bean>
    	
    	<bean id="sessionFactory"
    		class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
    		<property name="dataSource">
    			<ref local="dataSource"/>
    		</property>
    <!--		<property name="mappingResources">
    			<list>
    				<value> com/openv/spring/service/hibernate/UserInfo.hbm.xml
    				</value>
    			</list>
    		</property>-->
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect
    				</prop>
    				<prop key="hibernate.show_sql">true
    				</prop>
    			</props>
    		</property>
    	</bean>
    	
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    		destroy-method="close">
    		<property name="driverClassName">
    			<value>org.gjt.mm.mysql.Driver</value>
    		</property>
    		<property name="url">
    			<value>jdbc&#58;mysql&#58;//localhost&#58;3306/test</value>
    		</property>
    		<property name="username">
    			<value>root</value>
    		</property>
    		<property name="password">
    			<value>create</value>
    		</property>
    	</bean>
    </beans>
    then, i write a client :
    Code:
    ApplicationContext ac = new ClassPathXmlApplicationContext&#40;
    				"survey-context.xml"&#41;;
    SweepValidator sv = &#40;SweepValidator&#41; ac.getBean&#40;"sweepValidator"&#41;;
    
    logger.info&#40;"---------------" + sv.getSurveyService&#40;&#41;&#41;;
    i can get [email protected] 1

    Comment


    • #3
      Thanks.

      It turned out to be the simple thing that got forgotten in the crunch. I needed to alter the dispatecher servlet code so that the validator was declared as a bean and not as a class.
      --
      Richard Johnson

      Comment

      Working...
      X