aspose file tools*
The moose likes JSP and the fly likes when should i need to use beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "when should i need to use beans" Watch "when should i need to use beans" New topic
Author

when should i need to use beans

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
here i am developing a webapplication. i am creating a registration form in jsp so in the registraton form there is department list field}(combo box)
so i need to add the elements in the department filed from the database....
there are 2 ways' for doing this...
i can read the fileds from the database and add them to the hastable and then to session,
2nd way is using bean. i will set the values and read them in the jsp file



which is most preferred ???







:roll: :roll: :roll: :roll: :roll:


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
Sunny Kumar
Ranch Hand

Joined: Oct 27, 2005
Posts: 57
Use thef first appraoch if you want to preserve the values across pages but if you are using the value only for the form then I would recommend the 2nd approach.
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
hey i need those values only for one form... not in all forms...
so can i use beans...

but , i think, peformance wise Sessions are the best.


:roll:
can any one plzzz tell me according to performance of the application...
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
You would define a bean/VO/TO. There you would probably have all the properties present in the form. The combo field should be a collection e.g. ArrayList. Now what you would do is, bind your VO/TO with the request object as attribute and get that in your JSP. Then you just need to manipulate that object.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by saikrishna cinux:
[QB]hey i need those values only for one form... not in all forms...
but , i think, peformance wise Sessions are the best.


How??

We usually use session when its really required to do that. Your work can easily be done with request object. Avoid binding objects to session, which doesn't really qualify for that.
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
Originally posted by Adeel Ansari:
You would define a bean/VO/TO. There you would probably have all the properties present in the form. The combo field should be a collection e.g. ArrayList. Now what you would do is, bind your VO/TO with the request object as attribute and get that in your JSP. Then you just need to manipulate that object.


thanks for ur reply...
yes, i have used session for displaying the fields in the combobox but i have used vector not ArrayList,,
and some programmmers use HashTable for it..
which is the better among all..

I know that Vector class is synchronized and i thin it takes extra time...


:roll:
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by saikrishna cinux:
yes, i have used session for displaying the fields in the combobox


Session is not the suitable place in this case, as I have mentioned earlier. You had better do it with request object.

As you just need this from one page to another, request object is your best bet. We use session when we need something for the particular session, such as role associated with the current user, etc..


I know that Vector class is synchronized and i thin it takes extra time...


You are right. I would go for ArrayList.
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
oh thanx Mr ansari....
but what if i use beans in place of request object?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by saikrishna cinux:
oh thanx Mr ansari....
but what if i use beans in place of request object?


Oh Saikrishna, What do you mean by that?

You are confusing things. Request object and beans are not alternatives. You would add your beans in a collection and then place that collection in your request scope.

Are you gettin me?
[ December 21, 2005: Message edited by: Adeel Ansari ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: when should i need to use beans