Using int data type for member of Java Bean

Posted on 2006-04-29
Last Modified: 2012-06-21
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="*"/>
<head><title>Update Student</title></head>
Question by:Barry Cunney
    LVL 27

    Expert Comment

    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;
    LVL 17

    Author Comment

    by:Barry Cunney
    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.

    LVL 27

    Accepted Solution

    that is a MIME type, see  for example  
    >Is it a documented rule that the bean class member variable names should be lower case?
    You look at this.     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”

    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 {
       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.

    I hope I am not confusing you. Just stick to the standard and you won't have a problem.   rrz
    LVL 17

    Author Comment

    by:Barry Cunney
    That's brilliant help rrz

    Thanks again

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    jquery form plugin 4 147
    JTable - RowFilter & Columns Header. 3 129
    some methods private some are not 8 172
    spring example non maven 4 56
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    In the modern office, employees tend to move around the workplace a lot more freely. Conferences, collaborative groups, flexible seating and working from home require a new level of mobility. Technology has not only changed the behavior and the expe…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now