Olá Pessoal, estou apanhando demais para conseguir fazer funcionar o json com o struts 2;
- Copiei o arquivo q ven com o struts 2: struts2-json-plugin-2.1.8.1.jar para meu diretório lib do web-inf;
- depois configurei na minha action para que ela retorno um tipo json:
public class MostraNotaEntradaAjaxAction {
private int id_entrada;
private Ven_notaentrada vne;
@Action( value="mostraNotaEntradaAjax", results={
@Result(name="ok", type="json", params={"status","200"})
})
public String execute() {
try
{
System.out.println("mostra connection ajax");
Connection conn = new ConnectionFactory().getConnection();
vne = new Ven_notaentradaDAO(conn).getNotaById(id_entrada);
conn.close();
}catch (SQLException e) {
throw new RuntimeException(e);
}
return "{ id : "+ vne.getId_entrada().toString() +", desc : '"+vne.getDescricao()+"' }";
}
public Ven_notaentrada getVne() {
System.out.println("get vne ajax");
return vne;
}
public void setId_entrada(Integer idEntrada) {
System.out.println("set id_entrada ajax"+ ((Integer)id_entrada).toString());
id_entrada = idEntrada;
}
}
Mas qdo eu coloco type como json, eu mando restartar o tomcat daí ja vem o erro:
Unable to load configuration. - [unknown location]
Caused by: The Result type [json] which is defined in the Result annotation on the class [class gsa.action.MostraNotaEntradaAjaxAction] or determined by the file extension or is the default result type for the PackageConfig of the action, could not be found as a result-type defined for the Struts/XWork package [gsa.action#convention-default#] - [unknown location]
Pessoal, com certeza alguém já deve ter passado por isso, por favor, preciso de um help.