VRaptor Exception

7 respostas
d34d_d3v1l

Galera,

então, modifiquei o projeto do goodbuypra utilizar o SACI… ai no form de cadastro de novos usuários lançou esta exception que não estava sendo lançada antes…
O.o’

br.com.caelum.vraptor.http.InvalidParameterException: Exception when trying to instantiate Target(name=usuario, type=class br.loja.modelo.Usuario)  
    at br.com.caelum.vraptor.http.iogi.VRaptorInstantiator.handleException(VRaptorInstantiator.java:95)

PS: esta tudo funcionando bonito…
só o form pra cadastrar novo usuario q ta lançando esta exception

7 Respostas

Lucas_Cavalcanti

quais são os caused-by dessa exception?

d34d_d3v1l

oia a exception inteira:

Mai 16, 2012 6:23:39 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [default] in context with path [/vraptor-blank-project] threw exception
br.com.caelum.vraptor.http.InvalidParameterException: Exception when trying to instantiate Target(name=usuario, type=class br.loja.modelo.Usuario)
	at br.com.caelum.vraptor.http.iogi.VRaptorInstantiator.handleException(VRaptorInstantiator.java:95)
	at br.com.caelum.vraptor.http.iogi.VRaptorInstantiator.handleException(VRaptorInstantiator.java:97)
	at br.com.caelum.vraptor.http.iogi.VRaptorInstantiator.instantiate(VRaptorInstantiator.java:87)
	at br.com.caelum.vraptor.http.iogi.VRaptorInstantiator.instantiate(VRaptorInstantiator.java:80)
	at br.com.caelum.vraptor.http.iogi.IogiParametersProvider.instantiateOrAddError(IogiParametersProvider.java:80)
	at br.com.caelum.vraptor.http.iogi.IogiParametersProvider.instantiateParameters(IogiParametersProvider.java:73)
	at br.com.caelum.vraptor.http.iogi.IogiParametersProvider.getParametersFor(IogiParametersProvider.java:63)
	at br.com.caelum.vraptor.interceptor.ParametersInstantiatorInterceptor.getParametersFor(ParametersInstantiatorInterceptor.java:126)
	at br.com.caelum.vraptor.interceptor.ParametersInstantiatorInterceptor.intercept(ParametersInstantiatorInterceptor.java:83)
	at br.com.caelum.vraptor.core.LazyInterceptorHandler.execute(LazyInterceptorHandler.java:59)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:56)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
	at br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.java:71)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
	at br.com.caelum.vraptor.interceptor.InstantiateInterceptor.intercept(InstantiateInterceptor.java:48)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
	at br.com.caelum.vraptor.interceptor.FlashInterceptor.intercept(FlashInterceptor.java:83)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:56)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
	at br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:69)
	at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
	at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
	at br.com.caelum.vraptor.core.EnhancedRequestExecution.execute(EnhancedRequestExecution.java:44)
	at br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:91)
	at br.com.caelum.vraptor.ioc.spring.SpringProvider.provideForRequest(SpringProvider.java:58)
	at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:88)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at net.vidageek.mirror.provider.java.PureJavaMethodReflectionProvider.invoke(PureJavaMethodReflectionProvider.java:38)
	at net.vidageek.mirror.invoke.MethodHandlerByMethod.withArgs(MethodHandlerByMethod.java:54)
	at br.com.caelum.iogi.reflection.NewObject$Setter.set(NewObject.java:86)
	at br.com.caelum.iogi.reflection.NewObject.setProperty(NewObject.java:58)
	at br.com.caelum.iogi.reflection.NewObject.populateProperties(NewObject.java:51)
	at br.com.caelum.iogi.reflection.NewObject.valueWithPropertiesSet(NewObject.java:41)
	at br.com.caelum.iogi.ObjectInstantiator.instantiate(ObjectInstantiator.java:30)
	at br.com.caelum.iogi.MultiInstantiator.instantiate(MultiInstantiator.java:20)
	at br.com.caelum.vraptor.http.iogi.VRaptorInstantiator.instantiate(VRaptorInstantiator.java:85)
	... 44 more
Lucas_Cavalcanti

estranho…

vc tá passando algum parâmetro na requisição que termina em usuário?

vc tá passando algum parâmetro em que o atributo da classe possui dois setters recebendo tipos diferentes?

d34d_d3v1l

Lucas Cavalcanti:
estranho…

vc tá passando algum parâmetro na requisição que termina em usuário?

vc tá passando algum parâmetro em que o atributo da classe possui dois setters recebendo tipos diferentes?

Nops…

da uma olhada:

package br.loja.modelo;


import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@Entity
public class Usuario {

	@Id
	@GeneratedValue
	private Long id;
	
	private String nome;
	
	private String email;
		
	private String senha;
	
	private String perfil;

	@OneToMany(mappedBy="usuario", fetch = FetchType.LAZY)
	@Cascade(CascadeType.ALL)
	private List<Item> items;

	
	public String getPerfil() {
		return perfil;
	}

	public void setPerfil(String perfil) {
		this.perfil = perfil;
	}

	public void setItems(List<Item> items) {
		this.items = items;
	}

	public List<Item> getItems(){
		return items;
	}
	
	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}


	public Long getId() {
		return id;
	}


	public void setId(Long id) {
		this.id = id;
	}


	public String getEmail() {
		return email;
	}


	public void setEmail(String email) {
		this.email = email;
	}


	public String getSenha() {
		return senha;
	}


	public void setSenha(String senha) {
		this.senha = senha;
	}
	
	
}

e tenho o form pra cadastrar:

<form id="usuariosForm" action="<c:url value="/usuarios"/>" method="POST">
<fieldset>
<legend>Criar novo usuário</legend>
<label for="nome">Nome:</label>
<input id="nome" 
type="text" name="usuario.nome" value="${usuario.nome }"/>
<label for="login">Email:</label>
<input id="login" 
type="text" name="usuario.email" value="${usuario.email }"/>
<label for="senha">Senha:</label>
<input id="senha"  type="password" name="usuario.senha"/>
<label for="confirmacao">Confirme a senha:</label>
<input id="confirmacao" equalTo="#senha" type="password"/>
<label for="perfil">Perfil:</label>
<input type="text" name="usuario.perfil" value="${usuario.perfil }"/>

<button type="submit">Enviar</button>
</fieldset>
</form>

<script type="text/javascript">
$('#usuariosForm').validate({
	rules: {
		"usuario.nome": {
		required: true,
		minlength: 3
		},
		"usuario.email": {
		required: true
		},
		"usuario.senha": {
		reqiored: true
		}
		}
		});
</script>
Lucas_Cavalcanti

estranho… e vc tá recebendo um usuario no controller, certo?

isso acontece sempre?

d34d_d3v1l

sim…
entao estava funcional antes de utilizar o SACI…

d34d_d3v1l

eis os métodos no controller pro usuario:

@Get
	public void novo(){
	}
	
	@Post @Path("/usuarios")
	public void adiciona(Usuario usuario) throws Exception{
	if (dao.existeUsuario(usuario)) {
	validator.add(new ValidationMessage("Login já existe", "usuario.login"));
	}
	validator.onErrorUsePageOf(UsuariosController.class).novo();
	dao.salvar(usuario);
	result.redirectTo(ProdutosController.class).lista();
	}
Criado 16 de maio de 2012
Ultima resposta 17 de mai. de 2012
Respostas 7
Participantes 2