Class DefaultAddHandler

All Implemented Interfaces:
Handler, RouterNanoHTTPD.UriResponder
Direct Known Subclasses:
PropertiesAddHandler, RolesAddHandler, TasksAddHandler, UsersAddHandler

public abstract class DefaultAddHandler extends BaseHandler
Default handler for 'web/html/<entity>/add.html' templates. This one must be overwritten, because of mandatory db fields that might not be show on the GUI. The values to insert into database must be all defined if they are not nullable!
  • Constructor Details

    • DefaultAddHandler

      public DefaultAddHandler(String entity)
    • DefaultAddHandler

      public DefaultAddHandler(String entity, String errMsg)
  • Method Details

    • readData

      public HandlerResponse readData(BeetRootHTTPSession session, int id) throws Exception
      Description copied from class: BaseHandler
      Read data from DB that must be filled when the template is parsed. Used by index and view handlers.
      Overrides:
      readData in class BaseHandler
      Parameters:
      session - HTTP session
      id - db record id > 0 if a single record should be read otherwise < 0;
      Returns:
      response or null, null means success, response's status must be checked!
      Throws:
      Exception - exception
    • saveData

      public HandlerResponse saveData(BeetRootHTTPSession session) throws Exception
      Description copied from class: BaseHandler
      Save data to DB. Override for add handlers.
      Overrides:
      saveData in class BaseHandler
      Parameters:
      session - HTTP session
      Returns:
      response or null, null means success, response's status must be checked and must hold the id of the saved record!
      Throws:
      Exception - exception
    • extractSingleInputDiv

      protected String extractSingleInputDiv(BeetRootHTTPSession session, ResultSetMetaData rsmd, String columnName, String guiColName, int idx) throws Exception
      Extract one single input div with label and input tags from result set standing at current row. NOTE: Never call "set.next()" !
      Parameters:
      session - HTTP session
      rsmd - result set meta data
      columnName - column name as configured in 'web/<entity>/columns.cfg'
      guiColName - GUI column name as configured in 'web/<entity>/columns.cfg'
      idx - SQL result set column index
      Returns:
      html data extract <div>...</div>
      Throws:
      Exception - exception
    • extractSingleInputDiv

      protected String extractSingleInputDiv(BeetRootHTTPSession session, Map<String,String> data, ResultSetMetaData rsmd, String columnName, String guiColName, int idx) throws Exception
      Extract one single input div with label and input tags from result set standing at current row. NOTE: Never call "set.next()" ! Called in the retry case; 'data' contains cached data from previous user input.
      Parameters:
      session - HTTP session
      data - repost data (retry data)
      rsmd - result set meta data
      columnName - column name as configured in 'web/<entity>/columns.cfg'
      guiColName - GUI column name as configured in 'web/<entity>/columns.cfg'
      idx - SQL result set column index
      Returns:
      html data extract <div>...</div>
      Throws:
      Exception - exception
    • extractCustomSingleInputDiv

      public String extractCustomSingleInputDiv(BeetRootHTTPSession session, String val, ResultSetMetaData rsmd, String columnName, String guiColName, int idx) throws Exception
      Overwrite this method, if you need to add a custom field (HTML 'div'); e.g. when multiple user roles are used; in this case the 'div' is more likely consisting of 2 role assignment boxes instead of a simple input-'div' or use it for any custom 'div'. The 'div' is guaranteed to be inserted in the column-order as defined in the 'columns.cfg'.

      The return value of this method is essential:
      • Returns the data (including an empty character string): The HTML data is inserted into the template and further parsing of the columns for the HTML input elements is completed.
      • If 'null' is returned, the search for matching input elements for the current columns is continued, even if it is a transient column! Transient columns should be parsed in this method!
      Parameters:
      session - HTTP session
      val - repost data (only available in retry case)
      rsmd - result set meta data
      columnName - column name as configured in 'web/<entity>/columns.cfg'
      guiColName - GUI column name as configured in 'web/<entity>/columns.cfg'
      idx - SQL result set column index
      Returns:
      html data extract <div>...</div>
      Throws:
      Exception - exception
    • isSelect

      protected boolean isSelect(String columnName)
      Is this column a HTML select field?
      Parameters:
      columnName - column name
      Returns:
      true if so
    • getSelectValues

      protected String[] getSelectValues(String columnName)
      Get values for column name
      Parameters:
      columnName - column name
      Returns:
      select values
    • formatSingleValueForDB

      public String formatSingleValueForDB(BeetRootHTTPSession session, String val, String columnname)
      Description copied from class: BaseHandler
      Format single value before update / insert into DB. This method is useful if you want to store null values for date, time or time-stamp in the database. In the HTML user interface, the value would be displayed as '' (empty string), which is not a valid value in the database; in this case, it would need to be set to null. This is rarely the case, as date/time values are normally set or, if they are mandatory, should be set in the getAddMandatoryFields() method when creating a new record. It is therefore only possible for updates.
      Overrides:
      formatSingleValueForDB in class BaseHandler
      Parameters:
      session - HTTP session
      val - value
      columnname - column name
      Returns:
      formatted value
    • getAddMandatoryFields

      public abstract Map<String,Object> getAddMandatoryFields()
      Get additional mandatory fields of the table that are not present and mandatory fields in the GUI. They are usually the DB NOT NULL fields. Return the column/value pair within a map. The value must be an object that is representable as a string!
      Returns:
      column/value pair map
    • getResource

      public String getResource()
      Description copied from class: BaseHandler
      Get web resource file as it lies on the file system relatively to the started server process.
      Specified by:
      getResource in interface Handler
      Specified by:
      getResource in class BaseHandler
      Returns:
      web resource
    • getBeanClass

      public Class<?> getBeanClass()
      Get bean entity class that has been generated trough PLANT, self-written or null (then null in extract calls too).
      Overrides:
      getBeanClass in class BaseHandler
      Returns:
      bean entity class