Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaBeans - Am I missing out on something?

 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been hearing about JavaBeans for quite a while now. The only experience I had with them was in JSPs when you do <jsp:useBean>, and I didn't like it at all, because if I wanted to access that bean not from my page, but from my code, I was in for a bumpy ride...

So why do people like java beans so much? I didn't find them to be practical in JSP code, so I was wondering if maybe I am missing out on something...
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A bean is just a class that adheres to certain naming conventions (and ideally implements Serializable though for most practical purposes that's not required).
 
Josh Juneau
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaBeans usage for JSPs are kind of a "proper etticate" (sp?) deal. It is not proper to include java code within scriptlets throughout your JSP. You should use as little java code in your JSP as possible and reference a javabean to perform your business logic.
 
sushil pandey
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when u are developing a large application no doubt writing scriptlets will do the job.But what about code reuse and u can also change the java codes in beans inspite of going through all the code in your jsp file,but the most important advantage you get is of code reuseability

[ June 16, 2004: Message edited by: sushil pandey ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"JJ JavaDrinker" -

Welcome to the JavaRanch! We don't have many rules around the 'Ranch, but we do require your display name to follow the JavaRanch Naming Policy.
You can change it here.


Thanks! and welcome to the JavaRanch!
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I barely have any java code in my JSPs, and I don't use beans. I mostly use singletons and factories, and the advantage of that is that I can access them from both classess and JSPs and tags problem-free. It's not the same with beans.

Also, what about 1-tier 2-tier 3-tier applications? Aren't all applications custom and you can't really generalize them as "layers" ?
[ June 16, 2004: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JavaBean pattern is required for objects accessed from the page when using the built-in JSP actions as well as the JSTL tags. Following this pattern makes these object's APIs predictable.

If you are not using this pattern, or are eschewing the use of the JSP custom actions and the JSTL, you are diverging from what is considered 'best practices'.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. The same goes for properly layering (tiering) your application.
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you happen to know any good sources where I can read up more about it?

Thanks in advance...

P.S. why did you edit my last message? Did I say something "inapproporiate"?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, offensive language isn't any less offensive just because you abbreviate it.

You can read up on the JSTL as well as looking through the JSP 2.0 spec. Alos search for 'Model 2' information.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!