Class FormUtil

java.lang.Object
fc.web.forms.FormUtil

public class FormUtil extends Object
Misc. form related utilities.
  • Constructor Details

  • Method Details

    • fillSelect

      public static void fillSelect(Select select, List list, String message, Class beanClass, String valueMethodName, String htmlTextMethodName)
      Note: This method is almost never needed. Use the Select.useQuery(Connection, String) method instead.

      Fills in the specified select with values from the supplied list. This is intended to show a select widget corresponding to a lookup table in the database. The list will typically be returned by getAll/getWhere methods of some generated DBOMgr class.

      For example, given a lookup table object Foo and a corresponding manager object FooMgr and an empty previously-instantiated select:

      Select select = new Select("myselect")
      fillSelect(select, FooMgr.getAll(), 
        "--choose--", 
           Foo.class, "getID", 
           "getValue");
      
      and where table Foo has the following data
       Table Foo
       
        ID      Value
       -----------------------------------
        1     "lookup_one"
        2     "lookup_two"
        3     "lookup_three"
      
      will add the following values to the select:
      <option>--choose--</option>
      <option value=1>lookup_one</option>
      <option value=2>lookup_two</option>
      <option value=3>lookup_three</option>
      

      Parameters:
      select - a select object to be filled in
      list - list of objects of type beanClass. Typically this would be obtained via invoking the beanClassMgr.getAll() method
      message - an optional message to show as the first value of the select option (typically ---select-- or --choose an option-- etc.). Specify null to skip creating this optional message.
      beanClass - the
      invalid reference
      DBO
      class corresponding to some lookuptable in the database
      valueMethodName - the name of the method in the
      invalid reference
      DBO
      class which will be used to create the value for a radio button [ without "()"]
      htmlTextMethodName - the name of the method in the
      invalid reference
      DBO
      class which will be used to create the html text displayed to the user for a radio button [name should be without "()"]
      Throws:
      IllegalArgumentException - if an error occurred in getting the specified methods from the specified class and invoking them on the specified list
    • fillSelect

      public static void fillSelect(Select select, Map values, String message)
      Note: This method is almost never needed. Use the Select.useQuery(Connection, String) method instead.

      Fills in the specified select with values from the supplied map. This is intended to show a select widget corresponding to a lookup table in the database. The list will typically be returned by getAll/getWhere methods of some generated DBOMgr class.

      For example, given a lookup table object Foo and a corresponding manager object FooMgr and an empty previously-instantiated select:

      Select select = new Select("myselect")
      fillSelect(select, FooMgr.getAll(), 
        "--choose--", 
           Foo.class, "getID", 
           "getValue");
      
      and where table Foo has the following data
       Table Foo
       
        ID      Value
       -----------------------------------
        1     "lookup_one"
        2     "lookup_two"
        3     "lookup_three"
      
      will add the following values to the select:
      <option>--choose--</option>
      <option value=1>lookup_one</option>
      <option value=2>lookup_two</option>
      <option value=3>lookup_three</option>
      

      Parameters:
      select - a select object to be filled in
      values - A map containing the values for the select. For each key, value pair, the following will be generated for the select:
      message - an optional message to show as the first value of the select option (typically ---select-- or --choose an option-- etc.). Specify null to skip creating this optional message.
    • fillRadioGroup

      public static void fillRadioGroup(RadioGroup rg, List list, Class beanClass, String valueMethodName, String htmlTextMethodName)
      Fills in the specified radiogroup with values from the supplied list. This is intended to show radio groups corresponding to a lookup table in the database. The list will typically be returned by getAll/getWhere methods of some generated DBOMgr class.

      For example, given a lookup table object Foo and a corresponding manager object FooMgr and a empty previously-instantiated radio group:

      RadioGroup rg = new RadioGroup("myradio")
      fillRadioGroup(select, FooMgr.getAll(), 
           Foo.class, "getID", 
           "getValue");
      
      and where table Foo has the following data:
       Table Foo
       
        ID      Value
       -----------------------------------
        1     "lookup_one"
        2     "lookup_two"
        3     "lookup_three"
      
      will add those values to the radio group.
      Parameters:
      rg - a radio group object to be filled in
      list - list of objects of type beanClass. Typically this would be obtained via invoking the beanClassMgr.getAll() method
      beanClass - the
      invalid reference
      DBO
      class corresponding to some lookuptable in the database
      valueMethodName - the name of the method in the
      invalid reference
      DBO
      class which will be used to create the value for a radio button [ without "()"]
      htmlTextMethodName - the name of the method in the
      invalid reference
      DBO
      class which will be used to create the html text displayed to the user for a radio button [name should be without "()"]
      Throws:
      IllegalArgumentException - if an error occurred in getting the specified methods from the specified class and invoking them on the specified list
    • fillCheckboxGroup

      public static void fillCheckboxGroup(CheckboxGroup cbg, List list, Class beanClass, String valueMethodName, String htmlTextMethodName)
      Fills in the specified checkboxgroup with values from the supplied list. This is intended to show checkbox groups corresponding to a lookup table in the database. The list will typically be returned by getAll or getWhere methods of some generated DBOMgr class.

      For example, given a lookup table object Foo and a corresponding manager object FooMgr and a empty previously-instantiated checkbox group:

      CheckboxGroup rg = new CheckboxGroup("mycbgroup")
      fillCheckboxGroup(select, FooMgr.getAll(), 
           Foo.class, "getID", 
           "getValue");
      
      and where table Foo has the following data:
       Table Foo
       
        ID      Value
       -----------------------------------
        1     "lookup_one"
        2     "lookup_two"
        3     "lookup_three"
      
      will add those values to the checkbox group.
      Parameters:
      cbg - a checkbox group object to be filled in
      list - list of objects of type beanClass. Typically this would be obtained via invoking the beanClassMgr.getAll() method
      beanClass - the
      invalid reference
      DBO
      class corresponding to some lookuptable in the database
      valueMethodName - the name of the method in the
      invalid reference
      DBO
      class which will be used to create the value for a radio button [ without "()"]
      htmlTextMethodName - the name of the method in the
      invalid reference
      DBO
      class which will be used to create the html text displayed to the user for a radio button [name should be without "()"]
      Throws:
      IllegalArgumentException - if an error occurred in getting the specified methods from the specified class and invoking them on the specified list
    • fillSelectWithYears

      public static Select fillSelectWithYears(Select s, int startYear)
      Fills the specified select from years, starting with the specified year till the current year. No year option is pre-selected.
    • fillSelectWithYearsToday

      public static Select fillSelectWithYearsToday(Select s, int startYear)
      Fills the specified select from years, starting with the specified year. The current year (on the server) is pre-selected.
    • fillSelectWithYears

      public static Select fillSelectWithYears(Select s, int startYear, Calendar yearToSelect)
      Fills the specified select from years, starting with the specified year, upto the current year. The date from the specified calendar is pre-selected.
    • fillSelectWithYears

      public static Select fillSelectWithYears(Select s, int startYear, int endYear, Calendar cal)
      Fills the specified select from years, from the specified start and end years (both inclusive). The date from the specified calendar is pre-selected.
    • fillSelectWithMonths

      public static Select fillSelectWithMonths(Select s, boolean monthsAsText)
      Fills the specified select from years, starting with the specified year. monthsAsText specifies whether months are displayed as names or numbers. (true for names). No month is preselected.
    • fillSelectWithMonthsToday

      public static Select fillSelectWithMonthsToday(Select s, boolean monthsAsText)
      Fills the specified select from years, starting with the specified year. monthsAsText specifies whether months are displayed as names or numbers. (true for names). The current month (on the server) is preselected.
    • fillSelectWithMonths

      public static Select fillSelectWithMonths(Select s, boolean monthsAsText, Calendar cal)
      Fills the specified select from years, starting with the specified year. monthsAsText specifies whether months are displayed as names or numbers. (true for names). The current month from the specified calendar is is preselected.
    • fillSelectWithDays

      public static Select fillSelectWithDays(Select s)
      Fills the specified select from years, starting with the specified year. No day is pre-selected.
    • fillSelectWithDaysToday

      Fills the specified select from years, starting with the specified year. Today (on the server side) is preselected.
    • fillSelectWithDays

      public static Select fillSelectWithDays(Select s, Calendar cal)
      Fills the specified select from years, starting with the specified year. The day in the specified date is preselected.
    • toDate

      public static Date toDate(String year, String month, String day)
      Converts a year, month and day into a java.sql.Date
    • toTime

      public static Time toTime(String time)
      Converts a time string into a java.sql.Time. Time is of the format: HH:MM (for example: 1:23 or 01:23). Returns null if the string could not be parsed. (Hours upto 12 are allowed but not 13 or more). This method is suitable for a text box that takes 1-12 hours and a seperate am/pm select option next to it.
    • main

      public static void main(String[] args) throws Exception
      Throws:
      Exception