Olá pessoal, desde já fico grato a vocês pelo espaço cedido aqui
no guj para resolução de dúvidas.
Meu problema é o seguinte....
Estou utilizando Jquery com Json para recuperar uma lista
e mostrar o resultado na tela.
Quando eu acesso o endereço da jsp ele funciona
exemplo http://localhost:8084/Scp/jsp/teste.jsp
Só que, se eu acessar uma action e montar a página com tiles(http://localhost:8084/Scp/home.action)
ele não funciona... vocês sabem o que pode ser ?
<struts>
<package name="aurelio" extends="struts-default,json-default">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
</result-types>
</package>
</struts>
@ParentPackage("aurelio")
public class HomeAction extends ActionSupport {
@Action(value = "home", results = {
@Result(name = SUCCESS, location = "main", type = "tiles")})
public String gravaItem() {
return SUCCESS;
}
}
@ParentPackage("aurelio")
public class Teste extends ActionSupport {
private CrudBOGeneric crudBO;
public Collection<ItemEntity> listaItems;
public Teste() {
crudBO = new CrudBOGeneric();
listaItems = new ArrayList<ItemEntity>();
}
@Action(value = "giveMe", results =
@Result(name = "ok", type = "json"))
public String giveMe() {
try {
listaItems = crudBO.recuperaLista(new ItemEntity());
} catch (Exception ex) {
Logger.getLogger(Teste.class.getName()).log(Level.SEVERE, null, ex);
}
return "ok";
}
public Collection<ItemEntity> getListaItems() {
return listaItems;
}
public void setListaItems(Collection<ItemEntity> listaItems) {
this.listaItems = listaItems;
}
}
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://jakarta.apache.org/taglibs/display" prefix="display"%>
<script type="text/javascript" src="../js/jquery-1.4.4.min.js"></script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<script type="text/javascript">
function testingJsonAndAjax() {
$.getJSON('giveMe' ,{},function(json) {
itemsHtml = "<table>";
for (var i = 0; i < json.listaItems.length; i++) {
itemsHtml += '<tr>';
itemsHtml += '<td>' + json.listaItems[i].idItem + '</td>';
itemsHtml += '<td>' + json.listaItems[i].nmItem + '</td>';
itemsHtml += '<td>' + json.listaItems[i].dsItem + '</td>';
itemsHtml += '</tr>';
}
itemsHtml += '</table>';
$('#cartItems').html(itemsHtml);
$('#items').html(json.itemsN);
});
}
</script>
<body>
<a href="#" onclick="testingJsonAndAjax();">Refresh</a>
<div id="cartItems">
</div>
<div id="items">
</div>
</body>
</html>