Click to See Complete Forum and Search --> : Bean not found on my first Bean attempt


florida
02-05-2005, 11:53 AM
I am trying to create my first bean on my Windows XP. I loaded Tomcat 4.0 and can pull up JSP the Tomcat examples that came with the Tomcat software, but cant get my first bean to work!

Here is where I put my Bean file (called TheFirstBean.java) and compiled it in this location in a package name called num:
C:\Program Files\Apache Tomcat 4.0\webapps\examples\WEB-INF\classes\num

The TheFirstBean.java:

package num;

import java.util.*;

public class TheFirstBean
{
private String message = "Hello World";

public String getMes()
{
return (message);
}

public void setMes(String message)
{
this.message = message;
}
}


The JSP is located in this path:
C:\Program Files\Apache Tomcat 4.0\webapps\examples\jsp\num



<html>
<head>
<title>Untitled</title>
</head>
<body>
<jsp:useBean id="myID" class="num.TheFirstBean" />

<jsp:getProperty name="myID" property="message" />
</body>
</html>


After I pull up the page (http://localhost:8080/examples/jsp/num/tester.jsp), it gives me error message:
org.apache.jasper.JasperException: Cannot find any information on property 'message' in a bean of type 'num.TheFirstBean'
I cant seem to get any of my Bean to work. But the Tomcat examples that came with Tomcat work fine!
Please advise how I can get my first bean to work because I have tried many many hours.

Thanks

Khalid Ali
02-05-2005, 04:00 PM
Make the following changes in your code(shown in bold) and alwasy make sure that your method name is same as th eproperty its getting/setting.

public String getMessage()
{
return (this.message);
}

public void setMessage(String message)
{

florida
02-06-2005, 09:11 AM
thanks, i didnt know it looked or checked that??

ray326
02-06-2005, 06:48 PM
Originally posted by florida
thanks, i didnt know it looked or checked that??
That's all it looks for. Bean "properties" are defined by the names of their getters/setters.

florida
02-06-2005, 08:27 PM
I guess it confuses me because I thought all of Java was case sensitive so the property with message in it:

<jsp:getProperty name="myID" property="message" />

would have lower case here instead of uppercase:

public String getMessage()
{
return (this.message);
}

public void setMessage(String message)
{


But in this case its not looking at that as case sensitive?

ray326
02-07-2005, 01:00 AM
It's still case sensitive, it's just that JavaBeans are simply classes with empty constructors and a specific naming protocol for some of their methods. There are other bits to the "protocol" but those are the main ones.

When you use the getProperty tag, the name must match exactly the bean instance name in the useBean tag. The property name implies the associated methods. The property name "message" implies getMessage() and setMessage() getters and setters. The JavaBean container relies on reflection of the public aspects of the bean class.

florida
02-07-2005, 06:54 AM
Thanks!