• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding jsp:useBean  RSS feed

 
Roshini Sridharan
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Mr.Ben - Sorry for the usage of word]

Hi,

I am trying to use JavaBean class from my JSP page.

I have a class that contains members variables, relevant getter and setter methods, the thing is it has around 15 members and i don't want to use individual set/get method to set and retrieve the values from my jsp page.. Instead i want to use a parameterized constructor that takes one argument and retrieves me the relevant values from the database and populates the members.. so that i create an instance of the bean and access it values using the JSTL tags..

1. Is there any concept of invoking parameterized constructor concept using jsp:useBean
2. If yes, would like to know more on it
3. If no, what is the other way around that i have to send parameterised value my bean constructor to assign some dynamic value to its properties in one stroke.

Pls let me know ur thoughts on this..

Thanx in advance

Regards
Roshini.S

[ July 07, 2006: Message edited by: roshini sridhar ]
[ July 07, 2006: Message edited by: roshini sridhar ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
roshini sridhar,
Welcome to JavaRanch!

In an effort to help you get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.
In particular, please see EaseUp to find out how using the word Urgent in your subject line or post body will usually result in slower responses.

Again, welcome to JavaRanch and good luck with your question.
-Ben
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The useBean tag will always instanciate your beans with the zero argument constructor.

An alternative would be to instanciate your bean from the controller servlet and an bind it to the desired scope before forwarding to your JSP.

Then the JSP doesn't need to be concerned with how the bean is instanciated.
 
Roshini Sridharan
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr.Ben ,

Thanks for the suggestion, i will do that..

Good Day.

Regards
Roshini.S
 
Jacob Fenwick
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some questions about jsp:useBean also that are closely related to this.
1. Did roshini mean he was instantiating the bean inside a tag, or inside a jsp?
2. If you instantiate a bean inside a jsp using jsp:useBean, can you access that instantiated bean inside of a tag? What about a scriptlet?
3. If you put a jsp:setProperty tag inside a jsp:useBean tag, will the jsp:setProperty happen before the bean's constructor? I would assume not, but if the jsp:setProperty DOES happen first, roshini could have passed the variable through the request as a parameter, then used that variable in the constructor to do whatever he needed.
EDIT: Nope, constructor happens first. I guess the only way to do it is question 4...
4. Ben, How do you go about binding a bean to a scope?

[ July 07, 2006: Message edited by: Jacob Fenwick ]
[ July 07, 2006: Message edited by: Jacob Fenwick ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jacob Fenwick:

4. Ben, How do you go about binding a bean to a scope?

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jacob Fenwick:

2. If you instantiate a bean inside a jsp using jsp:useBean, can you access that instantiated bean inside of a tag? What about a scriptlet?


The useBean tag will bind the bean to the specified scope for you.
Your tag can get a reference to it by looking in the specified scope:
 
Jacob Fenwick
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben!
 
Roshini Sridharan
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx a lot Mr.Ben it worked fine.

Could not post the status immediately..

Thankyou for your time.

Regards
Roshini.S
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!