Link to home
Start Free TrialLog in
Avatar of dgomesbr
dgomesbrFlag for Brazil

asked on

[STRUTS 2.1.6] SessionAware does not inject session Object into Action

Hello guys,

   Once more here I come with a question of s2, i'm a beginner at it and got some trouble finding examples.

   I'm build a menu service wich depends upon a login, wich is give when the user enter at start page. Once the login has been made, I store the user object into the session by doing the follow:

 

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
    ....
             
    // verifica se o parametro do CPF veio no get e tenta logar o usuario
    if (!StringUtils.isBlank(request.getParameter(USER_CPF_REQUEST))) {
   
    if ( doLogin(request, session) ) {
       return Action.SUCCESS;
    }

and then the doLogin method

    Usuario usuario = getServico().buscar( Long.valueOf(cpf) );
    //Caso o usuário exista, guarda na session
    if (usuario != null){
        session.setAttribute(USER_HANDLE, usuario);
        return true;
    }

Now comes the problem, I have a MenuBean injected on the MenuAction by the following xml piece on ApplicationContext.xml

<bean id="menuService" class="br.com.autenticis.renacon.ejb.MenuBean" />

    <bean id="menuAction" scope="prototype" class="br.com.autenticis.renacon.actions.MenuAction">
        <constructor-arg ref="menuService" />
    </bean>

   

And the menuAction is declared as follow:

    public class MenuAction extends ActionSupport implements Preparable, SessionAware

By doing so I need to implement the session set with a private member
....
private Map<String, Object> session;
....
@Override
public void setSession(Map<String, Object> session) {
   this.session = session;
}
    The failing part of all its the method bellow, the session object is null at debugging:


      

    public String execute() {
                if ( session.containsKey( LoginInterceptor.USER_HANDLE) ){
                      Usuario u = (Usuario) session.get( LoginInterceptor.USER_HANDLE);
                      setMenu( servico.getMenuPerfil( u.getPerfil() ) );
                      return Action.SUCCESS;
                }
                
                return input();
          }

   Does anyone know why? or how to implement it? Looking at the code above, i need 'Perfil' from the user wich is logged on, if the session contains the key to the user object i get it and then use the perfil to populate the Menu through the setter and return SUCESS, otherwise it'll return INPUT wich will lead to the login screen.


Thanks in advance.



ASKER CERTIFIED SOLUTION
Avatar of dgomesbr
dgomesbr
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial