Let me see if I can help clear up the confusion.

A Java Bean is just a class which follows some basic rules to be considered
part of the JavaBeans component model. A Java Bean also has access to some
basic services which are part of the JavaBeans architecture and API but that
isn't important here.

The reason JSP states that it uses Java Beans, instead of plain ol classes, is
because the JSP environment expects that the classes used in the <jsp:useBean>
tag adhere to the basic bean requirements.

First, the class needs to implement a no args constructor. Otherwise it won't
be able to instantiate your class. That error has been posted on this list
before.

Second, in order to use the <jsp:setProperty> or <jsp:getProperty> tags the
class must either implement the standard naming convention for attribute
setters and getters or define a corresponding BeanInfo class.

e.g. If the class has a "name" attribute, it must either define the methods
below to modify the attribute, or it must define define a BeanInfo class with
the correct method names (truthfully I don't really know if the BeanInfo thing
works with JSP, I've never used it).

public void setName(String newName)
public String getName()

Also, I think that for a class to be considered a proper Java Bean that it must
be serializable, as you mentioned. But it appears that JSP doesn't care if the
class is serializable or not. Maybe that will change, maybe it won't, but right
now its moot.

Its really very simple to make a class a Java Bean, you probably developed many
already. Except for the serializable part, the example classes are beans.

If you want to know everything you need to know about beans, I recommend
reading the "Developing Java Beans" book by Robert Englander (published by
O'Reilly).

Hope that cleared things up a little.

-Brent

--- Chris <[EMAIL PROTECTED]> wrote:
> Part II in what's threatening to be my Pedantic Bean Series . . .
>
> When I first read about JSP, and I found out that they use Beans (not
> classes but Beans), I shit myself. Okay, no I didn't, but I was
> displeased because I actually have been a semi-successful freelance Java
> coder since the week Java came out, and I've never written a Bean! I
> always got away with just classes. So I was gonna have to find out
> precisely what a Bean really was and how to actually write one from
> scratch with WinEdit.
>
> I went to Sun's site and downloaded various tutorials and white papers
> and such (kind of a pain - most either didn't say anything or were
> poorly titled instructions on BeanBox - none seemed more recent than
> late 97), I came across the Bean Specification 1.0.1, and I read the
> whole damn thing.
>
> In it, a Bean is never precisely defined (it's a class, no wait, it's an
> object. It "doesn't inherit from any class or interface", hold on, it
> "must implement either Serializable or Externalizable". That was
> frustrating. Also irritating was the spec stressing that a Bean
> basically was a component that can be created and customized with a
> visual tool, and how there were plenty of things (like JDBC) that were
> better off as Class Libraries and not Beans - in other words, Everything
> Shouldn't Be a Bean. All well and good, but then JSP apparantly decides
> everything MUST be a bean - even things that have no use manipulation
> with a visual tool. So that seemed like a bad decision by the JSP guys.
>
> So now I'm frustrated, I've read some stuff that annoyed me (not hard),
> and I STILL don't really know what a bean is or how to write one. So I
> decide I'll just look at Sun's source code examples that ship with the
> JSWDK, and I'll follow their lead.
>
> And guess what?
> They're Not Beans!!!!!!!!!!
>
> They're just plain ol classes, the kind I actually know how to write.
>
> Which brings me to the place I could have started from if I wasn't
> hamming it up . . .
>
> Does JSP really only work with Beans (and not just plain Jane classes),
> and is the JSWDK just being nice (and if so what kind of a reference
> implementation is it? OR is there no Bean requirement at all - and if
> that's true, how come JSP says there is (heck, it calls the tag
> 'jsp:useBean")?
>
> All griping & insufferable garrulity aside, I would kind of like an
> answer.
>
>  - Chris
>
> P.S. I STILL don't know how to write a bean
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JSP-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to