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;
}
}