FileDocCategorySizeDatePackage
UserInfoBean.javaAPI DocExample8120Thu Jun 28 16:14:16 BST 2001com.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 validate user input and format output so it's suitable for HTML.
author
Hans Bergsten, Gefion software
version
1.0

Fields Summary
private static String
DATE_FORMAT_PATTERN
private static String[]
SEX_LIST
private static int
MIN_LUCKY_NUMBER
private static int
MAX_LUCKY_NUMBER
private String
birthDate
private String
birthDateInput
private String
emailAddr
private String
emailAddrInput
private String[]
interests
private String
luckyNumber
private String
luckyNumberInput
private String
sex
private String
sexInput
private String
userName
private boolean
isInitialized
Constructors Summary
Methods Summary
public java.lang.StringgetBirthDate()
Returns the birthDate property value


              
       
        return (birthDate == null ? "" : birthDate);
    
public java.lang.StringgetBirthDateFormatted()
Returns the birthDate property value, with all HTML special characters converted to HTML character entities

        return StringFormat.toHTMLString(getBirthDate());
    
public java.lang.StringgetEmailAddr()
Returns the emailAddr property value

        return (emailAddr == null ? "" : emailAddr);
    
public java.lang.StringgetEmailAddrFormatted()
Returns the emailAddr property value, with all HTML special characters converted to HTML character entities

        return StringFormat.toHTMLString(getEmailAddr());
    
public java.lang.String[]getInterests()
Returns the interests property value

        return interests;
    
public java.lang.String[]getInterestsFormatted()
Returns the interests property value, with all HTML special characters converted to HTML character entities

        String[] formatted = null;
        String[] interests = getInterests();
        if (interests != null) {
            formatted = new String[interests.length];
            for (int i = 0; i < interests.length; i++) {
                formatted[i] = StringFormat.toHTMLString(interests[i]);
            }
        }
        return formatted;
    
public java.lang.StringgetLuckyNumber()
Returns the luckyNumber property value

        return (luckyNumber == null ? "" : luckyNumber);
    
public java.lang.StringgetLuckyNumberFormatted()
Returns the luckyNumber property value, with all HTML special characters converted to HTML character entities

        return StringFormat.toHTMLString(getLuckyNumber());
    
public java.lang.StringgetPropertyStatusMsg()
Returns an HTML fragment with information about all invalid property values, or an empty String if all properties are valid.

        StringBuffer msg = new StringBuffer();
        if (!isInitialized()) {
            msg.append("Please enter values in all fields");
        }
        else if (!isValid()) {
            msg.append("The following values are missing or invalid: ");
            msg.append("<ul>");
            if (birthDate == null) {
                if (birthDateInput == null) {
                    msg.append("<li>Birth date is missing");
                }
                else {
                    msg.append("<li>Birth date value is invalid: " + birthDateInput);
                }
            }
            if (emailAddr == null) {
                if (emailAddrInput == null) {
                    msg.append("<li>Email address is missing");
                }
                else {
                    msg.append("<li>Email address value is invalid: " + emailAddrInput);
                }
            }
            if (luckyNumber == null) {
                if (luckyNumberInput == null) {
                    msg.append("<li>Lucky number is missing");
                }
                else {
                    msg.append("<li>Lucky number value is invalid: " + luckyNumberInput);
                }
            }
            if (sex == null) {
                if (sexInput == null) {
                    msg.append("<li>Sex is missing");
                }
                else {
                    msg.append("<li>Sex value is invalid: " + sexInput);
                }
            }
            if (userName == null) {
                msg.append("<li>User name is missing");
            }
            msg.append("</ul>");
            msg.append("Please enter new valid values");
        }
        else {
            msg.append("Thanks for telling us about yourself!");
        }
        return msg.toString();
    
public java.lang.StringgetSex()
Returns the sex property value

        return (sex == null ? "" : sex);
    
public java.lang.StringgetSexFormatted()
Returns the sex property value, with all HTML special characters converted to HTML character entities

        return StringFormat.toHTMLString(getSex());
    
public java.lang.StringgetUserName()
Returns the userName property value

        return (userName == null ? "" : userName);
    
public java.lang.StringgetUserNameFormatted()
Returns the userName property value, with all HTML special characters converted to HTML character entities

        return StringFormat.toHTMLString(getUserName());
    
private booleanisInitialized()
Returns true if at least one property has been set

        return isInitialized;
    
public booleanisValid()
Returns true if all property values have valid values (they are only set if the value is valid).

        return isInitialized() &&
            birthDate != null &&
            emailAddr != null &&
            luckyNumber != null &&
            sex != null &&
            userName != null;
    
public voidsetBirthDate(java.lang.String birthDate)
Sets the birthDate property value, if it's valid

        isInitialized = true;
        birthDateInput = birthDate;
        if (StringFormat.isValidDate(birthDate, DATE_FORMAT_PATTERN)) {
            this.birthDate = birthDate;
        }
    
public voidsetEmailAddr(java.lang.String emailAddr)
Sets the emailAddr property value, if it's valid

        isInitialized = true;
        emailAddrInput = emailAddr;
        if (StringFormat.isValidEmailAddr(emailAddr)) {
            this.emailAddr = emailAddr;
        }
    
public voidsetInterests(java.lang.String[] interests)
Sets the interests property value

        this.interests = interests;
    
public voidsetLuckyNumber(java.lang.String luckyNumber)
Sets the luckyNumber property value, if it's valid

        isInitialized = true;
        luckyNumberInput = luckyNumber;
        if (StringFormat.isValidInteger(luckyNumber, MIN_LUCKY_NUMBER,
            MAX_LUCKY_NUMBER)) {
            this.luckyNumber = luckyNumber;
        }
    
public voidsetSex(java.lang.String sex)
Sets the sex property value, if it's valid

        isInitialized = true;
        sexInput = sex;
        if (StringFormat.isValidString(sex, SEX_LIST, true)) {
            this.sex = sex;
        }
    
public voidsetUserName(java.lang.String userName)
Sets the userName property value

        isInitialized = true;
        this.userName = userName;