I'm a bit confused with the term bean in JSP eg. the tag <jsp:useBean ... > From what I understand, the term bean used here is referring to a simple java object.

Christopher Koenigsberg

It confused me too.

Originally Java Beans were intended for use in client-side GUI IDE systems where you would drag-and-drop them to build an application, and have them aware of changes and updates through the listener mechanism.

So a lot of the stuff in the Java Beans specification is for things that are useful in this kind of environment, for beans to document themselves to the person who is experimenting with them at design time in an IDE, and to work with registering listeners and notifications, when things change in the application built with them.

I have a book on Java Beans which is only a couple of years old, but the whole thing is basically about building components for these client-side, design-time drag-and-drop application builder GUI IDE's, with registered listeners for property changes.

So virtually none of the book is useful at all, for server-side design where you are not going to use any of these GUI features.

On the server side (working with servlets and JSP), at first someone told me "a Java Bean is just any class that implements Serializable".

But you don't need your class to say it implements Serializable, for basic use with servlets and JSP's.

You can really use just about any class at all, as a "bean" for the purpose of the jsp tags, as long as it has methods that you are interested in for your jsp bean tag use.

Mainly it makes everything a lot nicer, if you do follow the JavaBeans convention, for the classes you want to access via jsp bean tags, of having a member field named "FooBar", with corresponding "FooBar getFooBar()" and "setFooBar(FooBar innewfoobar)" methods.

Then some tools (like Struts with ActionFormBeans) will know to automatically call the set and get methods for the FooBar member field value, if your JSP is using a bean named "foobar;".

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact