Coloquei o exclude nesse método!
[code]@Post
@Path ("/grupo/salvar")
public void salvar(GrupoTela grupoTela, String itemselector) throws Exception {
List telas = new ArrayList();
String[] ids = itemselector.split(",");
for (String t : ids) {
Integer id = Integer.parseInt(t);
telas.add(telaService.getById(id));
}
if (grupoTela != null) {
if (grupoTela.getId() == null || grupoTela.getId() == 0) {
// return telaService.insert(tela);
if (grupoService.insert(grupoTela)) {
result.use(ExtJSJson.class).from(grupoTela).exclude("telas").success(false).serialize();
return;
}
} else {
// return telaService.update(tela);
if (grupoService.update(grupoTela)) {
result.use(ExtJSJson.class).from(grupoTela).success(true)
.serialize();
return;
}
}
}
result.use(ExtJSJson.class).from(grupoTela).success(false).serialize();
// return false;
}[/code]
Colocaria onde, testei em vários lugares…seria nesse metodo mesmo né? Obrigado.
sim, mas vc precisa colocar em todos os casos, vc colocou só em um.
Ok o método ficou assim…está correto agora?
[code]@Post
@Path ("/grupo/salvar")
public void salvar(GrupoTela grupoTela, String itemselector) throws Exception {
List telas = new ArrayList();
String[] ids = itemselector.split(",");
for (String t : ids) {
Integer id = Integer.parseInt(t);
telas.add(telaService.getById(id));
}
if (grupoTela != null) {
if (grupoTela.getId() == null || grupoTela.getId() == 0) {
// return telaService.insert(tela);
if (grupoService.insert(grupoTela)) {
result.use(ExtJSJson.class).from(grupoTela).exclude("telas").success(true).serialize();
return;
}
} else {
// return telaService.update(tela);
if (grupoService.update(grupoTela)) {
result.use(ExtJSJson.class).from(grupoTela).exclude("telas").success(true)
.serialize();
return;
}
}
}
result.use(ExtJSJson.class).from(grupoTela).exclude("telas").success(false).serialize();
// return false;
}
[/code]
Lucas, o mesmo erro ainda.
então não é essa propriedade que tá dando problema… tenta ver com outras (só as que forem classes da sua aplicação ou listas)
Tentei ela tem tipoMaterial e uma lista de telas…ja tentei as duas e não deu certo.
posta aqui a sua classe GrupoTela (só os atributos) e as classes mãe dela tb, plz
grupoTela
[code]public class GrupoTela implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Column(name = "id_grupo")
private Integer id;
@Column(name = "ds_grupo")
private String descricao;
@ManyToOne(fetch=FetchType.EAGER)
private TipoMaterial tipoMaterial;
@org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.ALL)
@OneToMany(fetch=FetchType.EAGER)
private List<Tela> telas;
[/code]
Tela
anotations estão nos gets.
private static final long serialVersionUID = 1L;
private Integer id;
private TipoTela tipoTela;
private String nome;
private String enderecoIp;
TipoMaterial
private static final long serialVersionUID = 1L;
private Integer id;
private String descricao;
tenta colocar com um data na frente:
...exclude("data.telas")
ou
..exclude("data.tipoMaterial")
Tentei isso com os dois e não deu…
[code]if (grupoService.insert(grupoTela)) {
result.use(ExtJSJson.class).from(grupoTela).exclude(“data.tipoMaterial”).success(false).serialize();
return;
}
} else {
// return telaService.update(tela);
if (grupoService.update(grupoTela)) {
result.use(ExtJSJson.class).from(grupoTela).exclude(“data.tipoMaterial”).success(false)
.serialize();
return;
}
}
}
result.use(ExtJSJson.class).from(grupoTela).exclude("data.tipoMaterial").success(false).serialize();
// return false;[/code]
faz esse teste então:
-copie essa classe pra sua aplicação:
/***
* Copyright (c) 2009 Caelum - www.caelum.com.br/opensource All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package br.com.caelum.vraptor.util.extjs;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
This file has been truncated. show original
e então faça:
ExtJSWrapper wrapper = new ExtJSWrapper(grupoTela);
wrapper.setSuccess(true);
result.use(Results.json()).withoutRoot().from(wrapper).include("data").serialize();
veja se funciona
Blz ma sonde coloco esse trecho? tiro alguma coisa e ponho isso no lugar?
no metodo salvar isso? obrigado.
ExtJSWrapper wrapper = new ExtJSWrapper(grupoTela);
wrapper.setSuccess(true);
result.use(Results.json()).withoutRoot().from(wrapper).include("data").serialize();
sim, substituindo o result.use que tá lá
Ok valeu, substitui e não deu certo!
deveria ficar assim o metodo?
[code]if (grupoTela != null) {
if (grupoTela.getId() == null || grupoTela.getId() == 0) {
// return telaService.insert(tela);
if (grupoService.insert(grupoTela)) {
ExtJSWrapper wrapper = new ExtJSWrapper(grupoTela);
wrapper.setSuccess(true);
result.use(Results.json()).withoutRoot().from(wrapper).include(“data”).serialize();
return;
}
} else {
// return telaService.update(tela);
if (grupoService.update(grupoTela)) {
ExtJSWrapper wrapper = new ExtJSWrapper(grupoTela);
wrapper.setSuccess(true);
result.use(Results.json()).withoutRoot().from(wrapper).include(“data”).serialize();
return;
}
}
}
ExtJSWrapper wrapper = new ExtJSWrapper(grupoTela);
wrapper.setSuccess(true);
result.use(Results.json()).withoutRoot().from(wrapper).include("data").serialize();
// return false;
}
[/code]
qual json ele tá gerando agora?
O mesmo {“data”: [{“id”: 9,“descricao”: “11”,“tipoMaterial”: {“id”: 19,“descricao”: “eddd”},“telas”: [true,
o erro aparece logo quando carrega a aplicação, nao preciso nem entrar na tela de grupo…
então lucas, essa sua solução é para o 3.4.0? estou usando o 3.4.1.
cara, tem algo de errado…
com a mudança que eu te passei ele não deveria mais tentar serializar o tipoMaterial nem a telas, acho que vc tá mudando no lugar errado.
tem certeza que o cara que tá gerando esse json é o método salvar?
Blz Lucas, vou tentar em um metodo de cada vez ok.
já te retorno.
Lucas houve uma mudança boa aqui mas não 100% ainda, coloquei no metodo de listar!
ficou assim:
[code]@Path ("/grupo/grid/dados.json")
public void grid(int start, int limit) throws Exception {
List base = grupoService.list();
List grupos = new ArrayList();
for (int k = start; (k < start + 10) && (k < base.size()); k++)
grupos.add(base.get(k));
ExtJSWrapper wrapper = new ExtJSWrapper(grupos);
wrapper.setSuccess(true);
result.use(Results.json()).withoutRoot().from(wrapper).include("data").serialize();
}[/code]
agora abre o modal mas a lista vem em branco…e o json gerado é esse {“success”: true}