You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mansour <ma...@yahoo.com> on 2007/05/26 16:39:46 UTC

session is null!

I am trying to setup a value in my session. IT works the first time I 
call the action, and breaks the second time.
I get null pointer exception. This code is from my constructor.


        Map session = ActionContext.getContext().getSession();
        if (session.containsKey("InvoiceManager"))
            this.invManager = (InvoiceManager) 
session.get("InvoiceManager");
        else {
            invManager = new InvoiceManager();
            session.put("InvoiceManager", invManager);
        }


Here' the exception:


java.lang.NullPointerException
    at action.InvoiceAction.<init>(InvoiceAction.java:25)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)




Any Idea what's going on ?


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: session is null!

Posted by Dave Newton <ne...@yahoo.com>.
--- Mansour <ma...@yahoo.com> wrote:
> (5) Or trying to access the session in the Action
> constructor.
> 
> I am not sure if this was my mistake. I would like
> to hear form some one.

As I've alluded to twice now, I believe it *is* your
mistake, at least if you're using SessionAware.

d.



 
____________________________________________________________________________________
Looking for earth-friendly autos? 
Browse Top Cars by "Green Rating" at Yahoo! Autos' Green Center.
http://autos.yahoo.com/green_center/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: session is null!

Posted by Mansour <ma...@yahoo.com>.
You missed one.

Paul Benedict wrote:
> Most people who have this problem do so because of four things: (1) 
> they are
> switching protocols from HTTP/HTTPS (2) they are switching contexts 
> (3) they
> are switching domains (4) they are invalidating the session.

(5) Or trying to access the session in the Action constructor.

I am not sure if this was my mistake. I would like to hear form some one.
By the way, can I save models on the ValueStack rather than the session ?


>
> -- Paul
>
> On 5/26/07, Dave Newton <ne...@yahoo.com> wrote:
>>
>> --- Mansour <ma...@yahoo.com> wrote:
>> > Thank you Dave for replying. I think I need a lot of
>> > help on this. The problem is even if I implement
>> > SessionAware, using chaining doesn't work as the
>> > setSession method is never called.
>>
>> Are you talking about the *second* action's
>> setSession()?
>>
>> Are you running a basicStack or stack that includes
>> the servletConfig interceptor on the action whose
>> setSession is *not* being called?
>>
>> At what point in the action object's lifecycle are you
>> attempting to access the session?
>>
>> d.
>>
>>
>>
>>
>> ____________________________________________________________________________________Got 
>>
>> a little couch potato?
>> Check out fun summer activities for kids.
>>
>> http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz 
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: session is null!

Posted by Paul Benedict <pb...@apache.org>.
Most people who have this problem do so because of four things: (1) they are
switching protocols from HTTP/HTTPS (2) they are switching contexts (3) they
are switching domains (4) they are invalidating the session.

-- Paul

On 5/26/07, Dave Newton <ne...@yahoo.com> wrote:
>
> --- Mansour <ma...@yahoo.com> wrote:
> > Thank you Dave for replying. I think I need a lot of
> > help on this. The problem is even if I implement
> > SessionAware, using chaining doesn't work as the
> > setSession method is never called.
>
> Are you talking about the *second* action's
> setSession()?
>
> Are you running a basicStack or stack that includes
> the servletConfig interceptor on the action whose
> setSession is *not* being called?
>
> At what point in the action object's lifecycle are you
> attempting to access the session?
>
> d.
>
>
>
>
> ____________________________________________________________________________________Got
> a little couch potato?
> Check out fun summer activities for kids.
>
> http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: session is null!

Posted by Dave Newton <ne...@yahoo.com>.
--- Mansour <ma...@yahoo.com> wrote:
> Thank you Dave for replying. I think I need a lot of
> help on this. The problem is even if I implement 
> SessionAware, using chaining doesn't work as the 
> setSession method is never called.

Are you talking about the *second* action's
setSession()?

Are you running a basicStack or stack that includes
the servletConfig interceptor on the action whose
setSession is *not* being called? 

At what point in the action object's lifecycle are you
attempting to access the session?

d.



       
____________________________________________________________________________________Got a little couch potato? 
Check out fun summer activities for kids.
http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: session is null!

Posted by Mansour <ma...@yahoo.com>.
Thank you Dave for replying. I think I need a lot of help on this.
The problem is even if I implement SessionAware, using chaining doesn't 
work as the setSession method is never called.


Dave Newton wrote:
> --- Mansour <ma...@yahoo.com> wrote:
>   
>> Still this didn't help. i am still getting nulls for
>> the session in Action 2. CAn some one point me to a 
>> link where I can get What I need ?
>>     
>
> At this point I have no idea what state your code is
> in. You shouldn't need to deal with ActionContext at
> all if you're implementing SessionAware and have the
> normal interceptor stack.
>
> I have never had any issues accessing anything from
> the session, although the only way I have done so is
> via SessionAware. I also haven't put any complex
> behavior, particularly any relying on the framework or
> interceptors, into action constructors.
>
> d.
>
>
>
>  
> ____________________________________________________________________________________
> The fish are biting. 
> Get more visitors on your site using Yahoo! Search Marketing.
> http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: session is null!

Posted by Dave Newton <ne...@yahoo.com>.
--- Mansour <ma...@yahoo.com> wrote:
> Still this didn't help. i am still getting nulls for
> the session in Action 2. CAn some one point me to a 
> link where I can get What I need ?

At this point I have no idea what state your code is
in. You shouldn't need to deal with ActionContext at
all if you're implementing SessionAware and have the
normal interceptor stack.

I have never had any issues accessing anything from
the session, although the only way I have done so is
via SessionAware. I also haven't put any complex
behavior, particularly any relying on the framework or
interceptors, into action constructors.

d.



 
____________________________________________________________________________________
The fish are biting. 
Get more visitors on your site using Yahoo! Search Marketing.
http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: session is null!

Posted by Mansour <ma...@yahoo.com>.
OK,
Here's what I was to get so far.
I need to store and retrieve EntityManagers in the session Map.
I am using action chaining. Action 1 can get the session using 
ActionContext.getContext.getSession(). However, action 2 always returns 
null. To make things easier for myself I created a Top Level Base class 
that implements SessionAware and extends ActionSupport, then I applied 
chain interceptor to Action 2 so that values from Action 1 can be coped 
to Action 2.

Still this didn't help. i am still getting nulls for the session in 
Action 2. CAn some one point me to a link where I can get What I need ?


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: session is null!

Posted by Mansour <ma...@yahoo.com>.
I followed the dox and created an Action that implements SessionAware. I 
set a break point and found the setSession is never called. Can someone 
explain please?



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: session is null!

Posted by Mansour <ma...@yahoo.com>.
I found out what I was looking for:
http://struts.apache.org/2.0.6/docs/how-do-we-get-access-to-the-session.html

but still wondering why would ActionContext.getContext().getSession() 
returns a session the first time it's called then it returns null?


Mansour wrote:
> I am trying to setup a value in my session. IT works the first time I 
> call the action, and breaks the second time.
> I get null pointer exception. This code is from my constructor.
>
>
>        Map session = ActionContext.getContext().getSession();
>        if (session.containsKey("InvoiceManager"))
>            this.invManager = (InvoiceManager) 
> session.get("InvoiceManager");
>        else {
>            invManager = new InvoiceManager();
>            session.put("InvoiceManager", invManager);
>        }
>
>
> Here' the exception:
>
>
> java.lang.NullPointerException
>    at action.InvoiceAction.<init>(InvoiceAction.java:25)
>    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native 
> Method)
>    at 
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
>
>    at 
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
>
>    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>    at java.lang.Class.newInstance0(Class.java:355)
>    at java.lang.Class.newInstance(Class.java:308)
>
>
>
>
> Any Idea what's going on ?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org