Pessoal,
Estou tentanto configurar uma Action para carregar o perfil de acesso de um usuário do banco.
Meu struts.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.devMode" value="true" />
<package name="usuario" extends="struts-default">
<action name="login" method="validaLogin" class="actions.LoginAction">
<result name="error">/index.jsp</result>
<result name="input">/index.jsp</result>
<result>/administrador/menu.jsp</result>
</action>
<action name="insereUsuario" class="actions.InsereUsuarioAction">
<result name="input">/usuario.jsp</result>
<result>/usuario.jsp</result>
</action>
<action name="listaUsuarios" class="actions.ListaUsuariosAction">
<result>/listaUsuarios.jsp</result>
</action>
<action name="removerUsuario!*" method="removeLista" class="actions.RemoverUsuarioAction">
<result name="erroServicoUsuario">/erroServicoUsuario.jsp</result>
<result>/usuario.jsp</result>
</action>
<action name="removerUsuario!*" method="removeUmUsuario" class="actions.RemoverUsuarioAction">
<result name="erroServicoUsuario">/erroServicoUsuario.jsp</result>
<result>/usuario.jsp</result>
</action>
<action name="montaPerfil" class="actions.MontaMenuAction">
<result>/administrador/listaPerfil.jsp</result>
</action>
</package>
</struts>
A Action, no caso é “montaPerfil”
Criei a página listaPerfil.jsp
<%@ taglib prefix="s" uri="/struts-tags"%>
<p>Perfil</p>
<s:if test="perfil.size > 0">
Entrou
<table>
<s:iterator value="perfil">
<tr id="row_<s:property value="id"/>">
<td>
<s:property value="id" />
</td>
<td>
<s:property value="descricao" />
</td>
<td>
</td>
</tr>
</s:iterator>
</table>
</s:if>
Que deve ser carregada na pagina menu.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Menu Principal</title>
<link rel="StyleSheet" href="tree.css" type="text/css">
<script type="text/javascript" src="tree.js"></script>
</head>
<body>
AQUI !
<s:div id="listaperfil"
href="montaPerfil.action"
listenTopics="listaPerfilTopic"
theme="ajax"
showLoadingText="true"
errorText="Um erro aconteceu"
loadingText="Carregando perfil" ></s:div>
</body>
</html>
O problema é que a Action não é nem chamada. Eu coloquei umas mensagens pra ver se está aperecendo, mas não acontece nada:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package actions;
import com.opensymphony.xwork2.ActionSupport;
import Impl.Menuimpl;
import com.opensymphony.xwork2.Action;
import java.util.List;
import mapIntelligence.Funcao;
/**
*
* @author danielti
*/
public class MontaMenuAction extends ActionSupport {
private Menuimpl servico;
private List<Funcao> funcao;
public MontaMenuAction(){
}
public MontaMenuAction(Menuimpl servico){
servico = servico;
}
public String execute() throws Exception{
System.err.println("Entrou no Action");
funcao=servico.monta();
return Action.SUCCESS;
}
public Menuimpl getServico() {
return servico;
}
public void setServico(Menuimpl servico) {
this.servico = servico;
}
public List<Funcao> getFuncao() {
return funcao;
}
public void setFuncao(List<Funcao> funcao) {
this.funcao = funcao;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Impl;
import DAO.MenuDAO;
import java.util.List;
import mapIntelligence.Funcao;
/**
*
* @author danielti
*/
public class Menuimpl {
private MenuDAO menudao;
public Menuimpl(){
}
public Menuimpl(MenuDAO menudao){
this.menudao = menudao;
}
public List<Funcao> monta(){
System.err.println("Entrou no Impl");
return this.getMenudao().montaPerfil();
}
public MenuDAO getMenudao() {
return menudao;
}
public void setMenudao(MenuDAO menudao) {
this.menudao = menudao;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package DAO;
import com.opensymphony.xwork2.ActionContext;
import java.util.List;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;
import mapIntelligence.Funcao;
/**
*
* @author danielti
*/
public class MenuDAO {
private EntityManager entityManager;
private EntityManagerFactory entityManagerFactory;
public MenuDAO(){
}
public MenuDAO(EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
this.entityManager = this.entityManagerFactory.createEntityManager();
}
public List<Funcao> montaPerfil(){
System.err.println("Montando o Perfil");
Map sessao = ActionContext.getContext().getSession();
Query query = this.getEntityManager().createNamedQuery("Acesso.MontaPerfil");
query.setParameter("usuarioid", sessao.get("usuario_id"));
System.err.println("Leu o Peril");
return query.getResultList();
}
public EntityManager getEntityManager() {
return entityManager;
}
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
public EntityManagerFactory getEntityManagerFactory() {
return entityManagerFactory;
}
public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}
}
Bom pessoal, outras sugestões também são bem-viondas, porque sou iniciante e estou aprendendo ainda.
Obrigado pela paciência.