Example: Universal dialog data bean class

This example data bean class implements a universal dialog with several user interface elements.


package com.ibm.commerce.tools.test;

import java.sql.Timestamp;
import java.util.*;
import com.ibm.commerce.beans.SmartDataBeanImpl;
import com.ibm.commerce.tools.common.ui.HTMLOption;

public class UDBean2 extends SmartDataBeanImpl {

private static final String COPYRIGHT =
com.ibm.commerce.copyright.IBMCopyright.SHORT_COPYRIGHT;

private String name = null;
private String password = null;
private String description = null;
private String lastUpdated = null;
private int age = 0;
private boolean isManager = false;
private Timestamp serviceDate = null;
private Timestamp anotherDate = null;
private double salary = 0;
private Vector gender = null;
private Vector favoriteColor = null;
private Vector interest = null;
private Vector certificates = null;

/**
* constructor
*/
public UDBean2() {
super();
}

/**
* populate method comment.
*/
public void populate() throws Exception {
setName("Sample Person");
setAge(20);
setDescription("This is a sample person description");
setManager(false);
setServiceDate(new Timestamp(System.currentTimeMillis())); // today's date
setLastUpdated((new Date(1999,10,1)).toString());
setSalary(88888.88);
setPassword("password");

// set favorite color selection (single selection)
// - HTMLOption() class takes three parameters - value, display text and selected boolean
// - returned object can be any Collection, not necessarily Vector (however, the Notebook/Wizard/Dialog widgets can only generate JavaScript code for Vector) 
Vector options = new Vector();
options.add(new HTMLOption("1", "red", false));
options.add(new HTMLOption("2", "blue", true));
options.add(new HTMLOption("3", "green", false));
setFavoriteColor(options);

// set interest selection (multiple selection)
// - notice the fourth optional parameter (ie. false) to indicate this text is final (not a resource bundle key)
options = new Vector();
options.add(new HTMLOption("s", "Sports", false, false)); 
options.add(new HTMLOption("m", "Movies", true, false));
options.add(new HTMLOption("b", "Books", true, false));
options.add(new HTMLOption("v", "Video Games", true, false));
setInterest(options);

// set gender selection (radio buttons) 
options = new Vector();
options.add(new HTMLOption("m", "male", true));
options.add(new HTMLOption("f", "female", false));
setGender(options);

// set certificates selection (check box group) 
// - because check box doesn't have value, the first paramter of the HTMLOption() is used to represent the input element name instead in this usage. 
options = new Vector();
options.add(new HTMLOption("cert_db2", "db2", true));
options.add(new HTMLOption("cert_oracle", "oracle", false));
options.add(new HTMLOption("cert_was", "was", true));
options.add(new HTMLOption("cert_linux", "linux", false));
setCertificates(options);

// if a field is not set, it'll have a default null value in the HTML form
// Timestamp: current date
// String (including int, float, and so on): empty string
// Collection: empty collection
// setAnotherDate();
}

/**
* @return
*/
public int getAge() {
return age;
}

/**
* @return
*/
public String getDescription() {
return description;
}

/**
* @return
*/
public boolean isManager() {
return isManager;
}

/**
* @return
*/
public String getName() {
return name;
}

/**
* @return
*/
public double getSalary() {
return salary;
}

/**
* @param i
*/
public void setAge(int i) {
age = i;
}

/**
* @param string
*/
public void setDescription(String string) {
description = string;
}

/**
* @param b
*/
public void setManager(boolean b) {
isManager = b;
}

/**
* @param string
*/
public void setName(String string) {
name = string;
}

/**
* @param d
*/
public void setSalary(double d) {
salary = d;
}

/**
* @return
*/
public String getLastUpdated() {
return lastUpdated;
}

/**
* @param string
*/
public void setLastUpdated(String string) {
lastUpdated = string;
}

/**
* @return
*/
public String getPassword() {
return password;
}

/**
* @param string
*/
public void setPassword(String string) {
password = string;
}


/**
* @return
*/
public Timestamp getServiceDate() {
return serviceDate;
}

/**
* @param timestamp
*/
public void setServiceDate(Timestamp timestamp) {
serviceDate = timestamp;
}

/**
* @return
*/
public Vector getCertificates() {
return certificates;
}

/**
* @return
*/
public Vector getFavoriteColor() {
return favoriteColor;
}

/**
* @return
*/
public Vector getGender() {
return gender;
}

/**
* @return
*/
public Vector getInterest() {
return interest;
}

/**
* @param vector
*/
public void setCertificates(Vector vector) {
certificates = vector;
}

/**
* @param vector
*/
public void setFavoriteColor(Vector vector) {
favoriteColor = vector;
}

/**
* @param vector
*/
public void setGender(Vector vector) {
gender = vector;
}

/**
* @param vector
*/
public void setInterest(Vector vector) {
interest = vector;
}

/**
* @return
*/
public Timestamp getAnotherDate() {
return anotherDate;
}

/**
* @param timestamp
*/
public void setAnotherDate(Timestamp timestamp) {
anotherDate = timestamp;
}

}