Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 132,639 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,082 people online right now. Registration is fast and FREE... Join Now!




Populating Bean Problem

 
Reply to this topicStart new topic

Populating Bean Problem

>>codingGeek<<
post 11 Oct, 2008 - 05:59 AM
Post #1


New D.I.C Head

*
Joined: 12 Jun, 2008
Posts: 28



Thanked 1 times
My Contributions


My servlet won't populate my bean. I have the necessary import, I declare and instantiate my bean class, then I tell the BeanUtilities to populate the bean with my bean class as the first parameter and the HttpServlet request as the second parameter.

I have verified that there is actual data being returned in the "request". However, my bean is not being populated.

I am using TomCat 6.0 to run my server at the localhost.

I am pretty sure it has to do something with my setup and where the coreservlet.jar is located at.

My instructor said to access the project properties build path and add external jar then ensure it is selected in module dependencies. However, this is not working.

Can anyone help?
User is offlineProfile CardPM

Go to the top of the page

>>codingGeek<<
post 11 Oct, 2008 - 08:56 AM
Post #2


New D.I.C Head

*
Joined: 12 Jun, 2008
Posts: 28



Thanked 1 times
My Contributions


I am pretty sure I am having a setup problem here.

I have verified that data is being submitted and my servlet is receiving that data. However, the bean is not being populated.

I have my .jar files in the WEB-INF lib folder, I have ensured they are in the build path, and I have selected them as module dependencies. However, I still get no bean data.


Help, please!
User is offlineProfile CardPM

Go to the top of the page

>>codingGeek<<
post 11 Oct, 2008 - 06:30 PM
Post #3


New D.I.C Head

*
Joined: 12 Jun, 2008
Posts: 28



Thanked 1 times
My Contributions


Maybe my call to my bean class is incorrect? Does anyone know if this is the right sequence of statement to populate a bean in a servlet?

CODE


public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
    RegistrationForm form = new RegistrationForm();  //Stores the bean
    BeanUtilities.populateBean(form, request); //Handles retrieving the
                                                                     // form data

....
}



The strange thing is when I utilize request.getParameter() to check if I am receiving any data in the request, I am. However, it is not populating the bean. And, I have met all the requirements of a bean, such as no constructor/empty constructor and all the get and set methods map to the elements in my form.

I am missing something simple and I just can't figure it out.

Here is my bean class (RegistrationForm)

CODE

public class RegistrationForm
{
          private String FirstName; //Stores the first name
          private String LastName; //Stores the last name
          private String Email; //Stores the email address
          private String Classification; //Stores the classification
          private String[] Beverages; //Stores the selected beverages
          private String ParticipationLevel; //Stores the selected participation
          private int BreakDuration = DEFAULT_BREAK; //Stores the break duration
          
          private static final int MIN_BREAK = 1; //Minimum value for snack break
          private static final int MAX_BREAK = 24; //Maximum value for snack break
          private static final int DEFAULT_BREAK = Integer.MIN_VALUE;
          
          //Sets the first name to specified value
          public void setFirstName(String fname)
          {
            FirstName = fname;
          }
          
          //Sets the last name to specified value
          public void setLastName(String lname)
          {
            LastName = lname;
          }
          
          //Sets the email to specified value
          public void setEmail(String email)
          {
            Email=email;
          }

          //Sets the classification to the specified value
          public void setClassification(String classify)
          {
            Classification = classify;
          }
          
          //Sets the beverages to the specified value(s)
          public void setBeverages(String[] drinks)
          {
              Beverages = drinks;
          }
          
          public void setBeverages(String drinks, int i)
          {
              Beverages[i] = drinks;
          }
          //Sets the participation level to the specified value
          public void setParticipationLevel(String attendance)
          {
            ParticipationLevel = attendance;
          }
          
          //Sets the break duration to the specified value
          public void setBreakDuration(int duration)
          {
            BreakDuration = duration;
          }
          
          //Returns the stored first name
          public String getFirstName()
          {
              return FirstName;
          }
          
          //Returns the stored last name
          public String getLastName()
          {
              return LastName;
          }
          
          //Returns the stored email
          public String getEmail()
          {
              return Email;
          }
          
          //Returns the stored classification
          public String getClassification()
          {
              return Classification;
          }
          
          //Returns the stored beverage selections
          public String[] getBeverages()
          {
              return Beverages;
          }
          
          public String getBeverages(int i)
          {
              return Beverages[i];
          }
          //Returns the stored participation selection
          public String getParticipationLevel()
          {
              return ParticipationLevel;
          }
          
          //Returns the stored break duration
          public int getBreakDuration()
          {
              return BreakDuration;
          }

          //Determines if the form is empty
          public boolean isComplete()
          {
            return FirstName != "" && LastName != "" && Email != ""
                       && ParticipationLevel != "";
          }

          //Determines if the required fields are empty or if the break duration field
          //is invalid
          public boolean isValid()
          {
             return BreakDuration <= MAX_BREAK
                    && BreakDuration >= MIN_BREAK;
          }
          
          public boolean isEmpty()
          {
            return (FirstName == null || FirstName.equals(""))
                && (LastName == null || LastName.equals(""))
                && (Email == null || Email.equals(""))
                && (Classification == null || Classification.equals(""))
                && (ParticipationLevel == null ||
                              ParticipationLevel.equals(""))
                && Beverages == null
                && BreakDuration == DEFAULT_BREAK;
          }

          
}
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 04:30AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month