You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mallik <ma...@yahoo.com> on 2005/04/14 02:08:02 UTC

accessing session variables in java Bean(In business logic Layer)

Hi
I use plain java beans for model/business layer.
I have a question regarding accessing session variables in java Beans(In model
Layer). I can pass session variables from action class but is there any other
way I can access session variables directly by extending any class. 
Because I need "session.userID" every time I make an insert/update in the
database and I feel it is redundant passing session variables every time along
with the form data(DTO) to java bean.

My example java bean code is as follows

public class DoInsertBean
{   
	private DataSource dataSource = null;	
	public DoInsertBean(DataSource dataSource)
	{
		this.dataSource = dataSource;
	}	      
    
    public int insert(UserDTO user){
    //Insertion into database
    //need session variables here??
       }
}

Thanks,
Mallik


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/

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


Re: accessing session variables in java Bean(In business logic Layer)

Posted by Martin Gainty <mg...@hotmail.com>.
struts-config identifies a forward to an identifier
The identifier is associated with the implementted action Class
The action class contain execute methods which reference 
HTTPServletRequest/HTTPServletResponse parameters
which can getSesssion and setSession for whatever parameter you desire
Is there something specific you want?
Martin-
----- Original Message ----- 
From: "Mallik" <ma...@yahoo.com>
To: <us...@struts.apache.org>
Sent: Wednesday, April 13, 2005 8:08 PM
Subject: accessing session variables in java Bean(In business logic Layer)


> Hi
> I use plain java beans for model/business layer.
> I have a question regarding accessing session variables in java Beans(In 
> model
> Layer). I can pass session variables from action class but is there any 
> other
> way I can access session variables directly by extending any class.
> Because I need "session.userID" every time I make an insert/update in the
> database and I feel it is redundant passing session variables every time 
> along
> with the form data(DTO) to java bean.
>
> My example java bean code is as follows
>
> public class DoInsertBean
> {
> private DataSource dataSource = null;
> public DoInsertBean(DataSource dataSource)
> {
> this.dataSource = dataSource;
> }
>
>    public int insert(UserDTO user){
>    //Insertion into database
>    //need session variables here??
>       }
> }
>
> Thanks,
> Mallik
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Small Business - Try our new resources site!
> http://smallbusiness.yahoo.com/resources/
>
> ---------------------------------------------------------------------
> 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: accessing session variables in java Bean(In business logic Layer)

Posted by Jeff Beal <jb...@gmail.com>.
All of our application state (including the user) is kept in a
separate "session" object in the business layer.  (We use a stateful
session EJB, but you could easily write your own POJO for this.)  The
web session, then, only has a reference to this session object (and a
few other view-specific variables, for tracing page history and the
like).

-- Jeff

On 4/13/05, Mallik <ma...@yahoo.com> wrote:
> Hi
> I use plain java beans for model/business layer.
> I have a question regarding accessing session variables in java Beans(In model
> Layer). I can pass session variables from action class but is there any other
> way I can access session variables directly by extending any class.
> Because I need "session.userID" every time I make an insert/update in the
> database and I feel it is redundant passing session variables every time along
> with the form data(DTO) to java bean.
> 
> My example java bean code is as follows
> 
> public class DoInsertBean
> {
>         private DataSource dataSource = null;
>         public DoInsertBean(DataSource dataSource)
>         {
>                 this.dataSource = dataSource;
>         }
> 
>     public int insert(UserDTO user){
>     //Insertion into database
>     //need session variables here??
>        }
> }
> 
> Thanks,
> Mallik
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Small Business - Try our new resources site!
> http://smallbusiness.yahoo.com/resources/
> 
> ---------------------------------------------------------------------
> 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