FileDocCategorySizeDatePackage
UserInfoBean.javaAPI DocExample6502Tue Feb 28 11:34:06 GMT 2006com.ora.jsp.beans.userinfo

UserInfoBean

public class UserInfoBean extends Object implements Serializable
This class contains information about a user. It's used to show how a bean can be used to capture and validate user input.
author
Hans Bergsten, Gefion software
version
2.0

Fields Summary
private static String
DATE_FORMAT_PATTERN
private static String[]
GENDER_LIST
private static String[]
FOOD_LIST
private static int
MIN_LUCKY_NUMBER
private static int
MAX_LUCKY_NUMBER
private String
birthDate
private String
emailAddr
private String[]
food
private String
luckyNumber
private String
gender
private String
userName
Constructors Summary
Methods Summary
public java.lang.StringgetBirthDate()
Returns the birthDate property value


              
       
        return (birthDate == null ? "" : birthDate);
    
public java.lang.StringgetEmailAddr()
Returns the emailAddr property value

        return (emailAddr == null ? "" : emailAddr);
    
public java.lang.String[]getFood()
Returns the food property value

        return (food == null ? new String[0] : food);
    
public java.lang.StringgetGender()
Returns the gender property value

        return (gender == null ? "" : gender);
    
public java.lang.StringgetLuckyNumber()
Returns the luckyNumber property value

        return (luckyNumber == null ? "" : luckyNumber);
    
public java.lang.StringgetUserName()
Returns the userName property value

        return (userName == null ? "" : userName);
    
public booleanisBirthDateValid()
Validates the birthDate property

return
true if the property is set to a valid value, false otherwise.

        boolean isValid = false;
        if (birthDate != null &&
            StringFormat.isValidDate(birthDate, DATE_FORMAT_PATTERN)) {
            isValid = true;
        }
        return isValid;
    
public booleanisChineseSelected()
Returns true if the food property includes the marker for Chinese

        return isFoodTypeSelected("c");
    
public booleanisEmailAddrValid()
Validates the emailAddr property

return
true if the property is set to a valid value, false otherwise.

        boolean isValid = false;
        if (emailAddr != null &&
                 StringFormat.isValidEmailAddr(emailAddr)) {
            isValid = true;
        }
        return isValid;
    
private booleanisFoodTypeSelected(java.lang.String foodType)
Returns true if the food property includes the specified food type

        if (food == null) {
            return false;
        }
        boolean selected = false;
        for (int i = 0; i < food.length; i++) {
            if (food[i].equals(foodType)) {
                selected = true;
                break;
            }
        }
        return selected;
    
public booleanisFoodValid()
Validates the food property

return
true if the property is set to a valid value, false otherwise.

        boolean isValid = false;
        if (food == null ||
                 StringFormat.isValidString(food, FOOD_LIST, true)) {
            isValid = true;
        }
        return isValid;
    
public booleanisGenderValid()
Validates the gender property

return
true if the property is set to a valid value, false otherwise.

        boolean isValid = false;
        if (gender != null &&
                 StringFormat.isValidString(gender, GENDER_LIST, true)) {
            isValid = true;
        }
        return isValid;
    
public booleanisLuckyNumberValid()
Validates the luckyNumber property

return
true if the property is set to a valid value, false otherwise.

        boolean isValid = false;
        if (luckyNumber != null &&
                 StringFormat.isValidInteger(luckyNumber, MIN_LUCKY_NUMBER,
                   MAX_LUCKY_NUMBER)) {
            isValid = true;
        }
        return isValid;
    
public booleanisPastaSelected()
Returns true if the food property includes the marker for pasta

        return isFoodTypeSelected("p");
    
public booleanisPizzaSelected()
Returns true if the food property includes the marker for pizza

        return isFoodTypeSelected("z");
    
public booleanisUserNameValid()
Validates the gender property

return
true if the property is set to a valid value, false otherwise.

        boolean isValid = false;
        if (userName != null) {
            isValid = true;
        }
        return isValid;
    
public booleanisValid()
Returns true if all property values have valid values (they are only set if the value is valid).

        return isBirthDateValid() && isEmailAddrValid() &&
            isFoodValid() && isLuckyNumberValid() && 
            isGenderValid() && isUserNameValid();
    
public voidsetBirthDate(java.lang.String birthDate)
Sets the birthDate property value

        this.birthDate = birthDate;
    
public voidsetEmailAddr(java.lang.String emailAddr)
Sets the emailAddr property value

        this.emailAddr = emailAddr;
    
public voidsetFood(java.lang.String[] food)
Sets the food property value

        this.food = food;
    
public voidsetGender(java.lang.String gender)
Sets the gender property value

        this.gender = gender;
    
public voidsetLuckyNumber(java.lang.String luckyNumber)
Sets the luckyNumber property value

        this.luckyNumber = luckyNumber;
    
public voidsetUserName(java.lang.String userName)
Sets the userName property value

        this.userName = userName;