Spring + JSF : Erro ao fazer o submit

1 resposta
jmedeiros

Galera,

Quando eu tento fazer um submit na minha página eu recebo este erro:
É como o spring não inicializa-se o bean que faz o submit no caso meu UserForm.java!

Minhas configurações.

SEVERE: loginAction
java.lang.NullPointerException
        at src.UserForm.login(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
My applicationContext-hibernate.xml
<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="location">
			<value>classpath:jdbc.properties</value>
		</property>
	</bean>


	<bean id="dataSource"
		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName">
			<value>${jdbc.driverClassName}</value>
		</property>
		<property name="url">
			<value>${jdbc.url}</value>
		</property>
		<property name="username">
			<value>${jdbc.username}</value>
		</property>
		<property name="password">
			<value>${jdbc.password}</value>
		</property>
	</bean>

	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
		<property name="mappingResources">
			<list>
				<value>src/mapping/User.hbm.xml</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.MySQLDialect
				</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>

			</props>
		</property>
	</bean>


	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory">
			<ref local="sessionFactory" />
		</property>
	</bean>

	<bean id="txProxyTemplate" abstract="true"
		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
		<property name="transactionManager">
			<ref bean="transactionManager" />
		</property>
		<property name="transactionAttributes">
			<props>
				<prop key="save*">PROPAGATION_REQUIRED</prop>
				<prop key="remove*">PROPAGATION_REQUIRED</prop>
				<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
			</props>
		</property>
	</bean>


	<bean id="userDao" class="src.UserDaoHibernate">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>

	<bean id="userManager" parent="txProxyTemplate">
		<property name="target">
			<bean class="src.UserManager">
				<property name="dao">
					<ref bean="userDao" />
				</property>
			</bean>
		</property>
	</bean>

My applicatinContext-forms.xml

<bean id="user" class="src.UserForm" singleton="false">
		<property name="manager">
			<ref bean="userManager" />
		</property>
		<property name="user">
			<ref bean="userPojo" />
		</property>
</bean>

My applicationContext.xml

<bean id="userPojo" class="src.User" />

My UserForm.java

import java.util.logging.Level;
import java.util.logging.Logger;

public class UserForm {

	private String nome;
	private String telefone;
	private Logger logger = Logger.getLogger("com.corejsf");
	private UserManager manager;
	private User user;
	
	
	public void setManager(UserManager manager) {
		this.manager = manager;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	public String getTelefone() {
		return telefone;
	}
	public void setTelefone(String telefone) {
		this.telefone = telefone;
	}
	
	public String login(){
		try{
			
		user.setNome(this.nome);
		user.setTelefone(this.telefone);
		manager.cadastrarUsuario(user);
		
		return "sucess";
		}catch(Exception e){
		logger.log(Level.SEVERE, "loginAction", e);
		e.printStackTrace();
		return "error";
		}
	}
	
	
}

Se eu mesmo instanciar meus atributos manager e user no meu UserForm meu erro agora vai para a classe que extend o HibernateDaoSupport.

Não mais o que fazer!!!

My UserDaoHibernate.java

package src;

import java.util.Collection;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class UserDaoHibernate extends HibernateDaoSupport 
implements UserDao{



	public void inseri(User user) {
		 getHibernateTemplate().saveOrUpdate(user);
		 
		 if (logger.isDebugEnabled()) {
	            logger.debug("userId set to: " + user.getId());
	        }
	}

	public Collection listaUsuarios() {
		  return getHibernateTemplate().find("from User");
	}

}

Qualquer ajuda agradeco!

[color=red]Mensagem do moderador: Ao postar codigos utilize as tags [ code ] e [ /code ].[/color]

1 Resposta

keller

Olá,

Cara uma sugestao é você olhar os codigos
do livro Spring Live mais exatamente do capitulo 7.

É onde o author cobre: Spring + JSF + Hibernate
:arrow: http://www.sourcebeat.com/downloads/splive/equinox-jsf-ch11-completed.zip

Da uma olhada nos codigos e veja o que
voce esta fazendo de errado…

Valeu? Até… :thumbup:
[s]

Criado 30 de março de 2006
Ultima resposta 30 de mar. de 2006
Respostas 1
Participantes 2