Last active
December 15, 2015 23:49
-
-
Save iconte/5342934 to your computer and use it in GitHub Desktop.
- Vraptor / Javascript / JSON / Java / Trechos de codigo mostrando : - o js para montagem do json / chamada ajax com jquery ; - classe java do método controller Vraptor - classe java utilizada como parametro do metodo controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//metodo para montagem do json que vai bater com a classe java | |
getDadosFormulario:function(){ | |
var vaga=[]; | |
//atentar para o fato de que o name deve ser igual ao nome do objeto passado como parametro e suas propriedades | |
vaga.push({name:"vaga.nome",value: $("#titulo").val()}); | |
vaga.push({name:"vaga.salario",value: $("#salario").val()}); | |
vaga.push({name:"vaga.local",value: $("#local").val()}); | |
vaga.push({name:"vaga.descricao",value: $("#descricao").val()}); | |
return vaga; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//as chamadas ajax utilizaram a versao 1.8.0 da jquery | |
salvar:function(url){ | |
//1a alternativa de chamada ajax | |
//$.post(url,this.getDadosFormulario(),function(data,status,xhr){},"json"); | |
//2a alternativa | |
$.ajax({ | |
url: url, | |
data:this.getDadosFormulario(), | |
type:"POST" | |
}).done(function() { | |
alert('passou'); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//o objeto vaga sera preenchido corretamente | |
public void salvar(Vaga vaga) { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//a unica exigencia e que a classe seja serializable | |
public class Vaga implements Serializable{ | |
private String nome; | |
private String local; | |
private String descricao; | |
private BigDecimal salario; //ate mesmo tipos abstratos como BigDecimal funcionam! | |
public String getLocal() { | |
return local; | |
} | |
public void setLocal(String local) { | |
this.local = local; | |
} | |
public String getDescricao() { | |
return descricao; | |
} | |
public void setDescricao(String descricao) { | |
this.descricao = descricao; | |
} | |
public BigDecimal getSalario() { | |
return salario; | |
} | |
public void setSalario(BigDecimal salario) { | |
this.salario = salario; | |
} | |
public String getCodigo() { | |
return codigo; | |
} | |
public String getNome() { | |
return nome; | |
} | |
public void setNome(String nome) { | |
this.nome = nome; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment