us.souther.select
Class HolidayBean

java.lang.Object
  extended by us.souther.select.HolidayBean

public class HolidayBean
extends java.lang.Object

This is the model portion of an MVC app that demonstrates one way to build work with dynamic select boxes. In the real world this bean would most likely access a relational database to get the data. In order to keep this project entirely contained within a war file, a data structure (HolidayDB) was used instead. The basic concept is the same and this bean should be good enough to use as a starting point in a relational database app. Legal Notice:

This code was written for demonstration purposes only. The author of this code assumes no responsibility for damage resulting in it's use. You may do whatever you like with it but at your own risk. It is your responsibility to understand how it works and determine if it is dependable enough, stable enough, and secure enough for your intended purpose.

Since:
Sat Apr 23 15:56:51 EDT 2005
Author:
Ben Souther; ben@souther.us

Constructor Summary
HolidayBean()
          Creates a new HolidayBean.
HolidayBean(HolidayDB db, int month, java.lang.String key)
          Creates a new HolidayBean.
 
Method Summary
 java.lang.String getHolidaysAsOptions()
          Builds a filtered list of holidays as a set of HTML Select Option tags.
 java.lang.String getInfo()
          Shows the date that a selected holiday is celebrated on but only when the final form has been submitted.
 java.lang.String getIsFormEnabled()
          Used to toggle the disabled status of the form's enter button.
 java.lang.String getKey()
          This key is also used as the value portion in the option tags return from the getHolidaysAsOptions method.
 int getMonth()
          The month as a numeric string.
 java.lang.String getMonthsAsOptions()
          Builds a list of Months as a set of HTML Select Option tags.
static void main(java.lang.String[] args)
          For testing and debugging only.
 void setShowInfo(boolean showInfo)
          Unless this is specifically set to true, the getInfo mehod will return an empty string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HolidayBean

public HolidayBean()
Creates a new HolidayBean. This is the constructor that will be called when the JSP is first hit. It is necessary to have a zero argument constructor when using the "class" attribute of a jsp:useBean tag to instanciate the bean automatically when the JSP first loads.


HolidayBean

public HolidayBean(HolidayDB db,
                   int month,
                   java.lang.String key)
Creates a new HolidayBean. This is the constructor that the servlet (controller) will use when instanciating this bean.

Parameters:
db - The mock database containing the holiday information.
month - The month filter used to restrict the list of holidays. This value will be passed to the servlet as an HTML form parameter. It will come from the month select list in on the JSP.
key - The key needed to pull a specific holiday from the database. This value will be passed to the servlet as an HTML form parameter. It will come from the holiday select list on the JSP. If this arg is a blank string we will assume that the form submission was triggered by the onclick event of the month select list.
Method Detail

getMonthsAsOptions

public java.lang.String getMonthsAsOptions()
Builds a list of Months as a set of HTML Select Option tags.

Returns:
the list of months as HTML Select Options. If the month was passed into this bean's constructor, it will appear as a selected month. The bean is capable of building this list without any information from the JSP or Servlet. This method will return a full set of Option tags, even when the bean has been instanciated with the zero argument constructor.

getHolidaysAsOptions

public java.lang.String getHolidaysAsOptions()
Builds a filtered list of holidays as a set of HTML Select Option tags.

Returns:
The list of available holidays as HTML Select Option tags. If a key argument passed into this bean's constructor is not empty, it will cause that holiday to appear as selected. The list will be filtered by the month argument passed into the constructor. If this bean was instanciated with the zero argment constructor, this method will return an empty string.

getIsFormEnabled

public java.lang.String getIsFormEnabled()
Used to toggle the disabled status of the form's enter button. Read this property from either a jsp:getProperty tag or an EL expression inside of the HTML enter button.
Example: <input type="enter_button" value="Enter" ${holidayBean.isFormEnabled} />
or
<input type="enter_button" value="Enter" <jsp:getProperty name="holidayBean" property="isFormEnabled" /> />

Returns:
"" if the form is ready to be submitted, else " disabled".

getInfo

public java.lang.String getInfo()
Shows the date that a selected holiday is celebrated on but only when the final form has been submitted. The purpose is mainly to demonstrate how to restrict the submitting of a form until all the needed information has been gathered from the select boxes.

Returns:
a friendly message telling when this holiday is celebrated.

setShowInfo

public void setShowInfo(boolean showInfo)
Unless this is specifically set to true, the getInfo mehod will return an empty string. The purpose is mainly to demonstrate how to keep a form button disabled until all the needed information has been gathered from the select boxes.

Parameters:
showInfo - form information?

getMonth

public int getMonth()
The month as a numeric string. Readonly.

Returns:
the month

getKey

public java.lang.String getKey()
This key is also used as the value portion in the option tags return from the getHolidaysAsOptions method.

Returns:
The key for retrieving the holiday object.

main

public static void main(java.lang.String[] args)
For testing and debugging only.