Writing java bean class?

Hi All,

In my scenario,I am getting all pagelevel details from the database.

I mean Suppose in my web application 10 pages are there.for 10 pages, all details (like page title,button names,page header etc) based on user.per user it will vary .Some body have insert,update buttons ,some body not.

I was created java bean with static getters and setters for all pages to get the data and store.

I don't want to connect to the database to get the page details per every page.so,

its working for me.what happen if more than one user access the application.The details will effect to all when new user enter into the system?

any suggestions.....................................?

if I write non - static getters and setters ,I need to instantiate everypage.

its takes more memory ,In my web application I have above 75 pages.

solution?

[891 byte] By [Nagireddy_javaDevelopera] at [2007-10-2 19:45:49]
# 1
Create a session per user and store the bean in the session object as attributes.ram.
Madathil_Prasada at 2007-7-13 22:24:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

You mean using static getters and setters?

Could you provide sample code how to do that ?

my knowledge,

If the bean methods are static,at the time of setting the values ,i think it will effect to every user.becuase methods are related to the class.not object.so,created only one copy?

Nagireddy_javaDevelopera at 2007-7-13 22:24:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

No not static. Static would be shared across users and you dont want that to happen, do you? Your post mentions that each user has his own state/permissions etc - you cant use static objects for such implementations. Have a bean instance per user and store it in the user's session - that's how I would do it.

ram.

Madathil_Prasada at 2007-7-13 22:24:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
1)So,I need to pass the Class object to the session.setAttribute()right?2)Suppose I change my bean to instance bean,bean have above 20instance variables .I think performance point of view,Its not good.Because,if users are more than 20 what happend??
Nagireddy_javaDevelopera at 2007-7-13 22:24:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

I got one idea?tell me If I am wrong?

I have bean class now .

1)Will write one jsp page.in that page i will get the connection & values per user.

2)Then,Instantiate the bean class,set alll values to the bean.

3) I will include that page to the every page using

<jsp:include page="GetUserDetails.jsp" flush="true" />

It will work rigth?

I think no need to instantiate again in everypage.Because the GetUserDetails.jsp already instantiated ,that jsp i am including

?

Nagireddy_javaDevelopera at 2007-7-13 22:24:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

> 1)So,I need to pass the Class object to the

> session.setAttribute()

> right?

>

Well to be precise - you create an instance of the class (object) for each registered and logged in user and then yes - store the object as a session attribute

>

> 2)Suppose I change my bean to instance bean,bean have

> above 20instance variables .I think performance

> point of view,Its not good.

> Because,if users are more than 20 what happend?

>

You should probably think about 200 :). 20 users is not an issue wwhen you have sufficient hardware.

One option would be to store the user permission/preferences in the db and associate it with the user id. Infact for large applications that hold lots of user related data per user, that would be my preferred approach.

ram.

Madathil_Prasada at 2007-7-13 22:24:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...