Using int data type for member of Java Bean

Hi Guys,
I have problems using a member of data type int in Java Bean
Below are the relevant parts of my Java Bean class file, Student.class
private int Count;

public int getCount()
{
  return Count;
}
      
public void setCount(int Count)
{
    this.Count = Count;
}

JSP file which uses Student bean:
The below jsp file is actioned when I submit a form as part of another jsp file
It is simply set up to print out the Count and FirstName properties of the Student Java bean
It does print out the FirstName that I supply in the form correctly, but no matter which number I supply in Count in the form, 0(zero) is always returned for Count.
It is as if the Java Bean is not handling property of type int!
Maybe there is something else I need to be doing using another data type other than int or qualifying this more or soemething - Any advice appreciated.

<%@page contentType="text/html"%>
<%@page import="ie.nci.student.*"%>
<jsp:useBean id="student" scope="page" class="ie.nci.student.Student" />
<jsp:setProperty name="student" property="*"/>
<html>
<head><title>Update Student</title></head>
<body>
<%
    out.println(student.getCount());
      out.println(student.getFirstName());
      
%>
 
</body>
</html>
LVL 17
Barry CunneyAsked:
Who is Participating?
 
rrzConnect With a Mentor Commented:
>"text/plain"
that is a MIME type, see  for example   http://www.sympa.org/distribution/current/wwsympa/mime.types   
>Is it a documented rule that the bean class member variable names should be lower case?
You look at this.     http://java.sun.com/products/javabeans/docs/spec.html     But the relevent parts are below.
From the javabean specification,
8.8 Capitalization of inferred names.
When we use design patterns to infer a property or event name, we need to decide what rules
to follow for capitalizing the inferred name. If we extract the name from the middle of a normal
mixedCase style Java name then the name will, by default, begin with a capital letter.
Java programmers are accustomed to having normal identifiers start with lower case letters.
Vigorous reviewer input has convinced us that we should follow this same conventional rule
for property and event names.
JavaBeans Introspection
Sun Microsystems 58 10/12/97
Thus when we extract a property or event name from the middle of an existing Java name, we
normally convert the first character to lower case. However to support the occasional use of all
upper-case names, we check if the first two characters of the name are both upper case and if
so leave it alone. So for example,
“FooBah” becomes “fooBah”
“Z” becomes “z”
“URL” becomes “URL”

8.3
By default, we use design patterns to locate properties by looking for methods of the form:
public <PropertyType> get<PropertyName>();
public void set<PropertyName>(<PropertyType> a);
If we discover a matching pair of “get<PropertyName>” and “set<PropertyName>” methods
that take and return the same type, then we regard these methods as defining a read-write property
whose name will be “<propertyName>”. We will use the “get<PropertyName>” method
to get the property value and the “set<PropertyName>” method to set the property value. The
pair of methods may be located either in the same class or one may be in a base class and the
other may be in a derived class.
If we find only one of these methods, then we regard it as defining either a read-only or a writeonly
property called “<propertyName>”
By default we assume that properties are neither bound nor constrained (see Section 7).
So a simple read-write property “foo” might be represented by a pair of methods:
public Wombat getFoo();
public void setFoo(Wombat w);

Tere are a few "gottchas". Consider the following bean.
package test;
public class BeanTest implements java.io.Serializable {
   private boolean[] bHours = {false,true};
   private String RRZ = "me";
   private String Joe = "hello";
   public BeanTest(){
   }
   public void setbHours(boolean[] bHours){
          this.bHours = bHours;
   }
   public boolean[] getbHours(){
          return bHours;
   }
   public void setRRZ(String str){
                            RRZ = str;
   }
   public String getRRZ(){
          return RRZ;
   }
   public void setJoe(String str){
                            Joe = str;
   }
   public String getJoe(){
          return Joe;
   }
}
In a JSP the following display the correct result.
${myBean.RRZ}
${myBean.joe}
${myBean.bHours[0]}    

I hope I am not confusing you. Just stick to the standard and you won't have a problem.   rrz
0
 
rrzCommented:
Try it this way.  The field in the form shoud be "count".  
private int count;
public int getCount()
{
  return count;
}
     
public void setCount(int count)
{
    this.count = count;
}
0
 
Barry CunneyAuthor Commented:
Hi rrz@871311
Thank you very much for that - this was a big help
I am just learning Java Beans

Is it a documented rule that the bean class member variable names should be lower case? or is there some other reason for this?

I also noticed that in one of my jsp files I had enctype="text/plain" as one of the attributes for my form tag, and this also casue problems with numeric values being passed into the bean.

0
 
Barry CunneyAuthor Commented:
That's brilliant help rrz

Thanks again
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.