T - entity that will be handled by the datatables, represent one JPA entity.ID - the unique identifier of entity Tpublic abstract class AbstractDataTablesController<T,ID> extends java.lang.Object implements DataTablesController<T,ID>
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
JSON |
| Constructor and Description |
|---|
AbstractDataTablesController() |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
addRecord(T entity,
org.springframework.validation.BindingResult validationResult,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Validates an entity and if validation passes adds that record.
|
void |
configureTable(TableConfiguration<T,ID> tableConfig)
Takes a StandardTableConfiguration and uses is to configure the controller.
|
java.lang.String |
dashboardData(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Helper method to populate the transaction dashboard.
|
java.lang.String |
deleteRecord(ID id)
Deletes the record with unique identifier (such as primary key) id
|
java.lang.String |
editEntityUsingForm(T entity,
ID entityID,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Requests from the edit form will hit this method.
|
java.lang.String |
editRecord(ID id,
java.lang.Integer columnPosition,
java.lang.String value,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.springframework.ui.Model model)
Handles editing of records using the primary key, column position and new value for that column.
|
protected java.lang.String |
formatValueForDisplay(ID id,
java.lang.String value)
Method for subclasses to implement if needed, to format the returned value.
|
ApplicationSettings |
getAppSettings() |
java.lang.String |
getCustomUrl() |
DataTablesService<T,ID> |
getDataTablesService() |
java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> |
getDropDownFiller() |
java.util.Map<java.lang.String,java.lang.String> |
getDropDownValuesFor(java.lang.String key)
Methods for handling drop down values
|
T |
getEntity() |
protected java.lang.String |
getJsonFormattedDropDownValues(java.util.Map<java.lang.String,java.lang.String> values)
Gets a value from the dropDownFiller map using the key passed in, the return will be used to populate the drop down menu
when editing a value in the data tables that is of drop down type.
|
protected java.lang.String |
getJsonFormattedDropDownValues(java.lang.String key) |
org.apache.log4j.Logger |
getLog() |
TableConfiguration<T,ID> |
getTableConfig() |
java.lang.Class<T> |
getType() |
java.lang.String |
getViewName() |
java.lang.String |
init(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.springframework.ui.Model model)
Initializes the data table, this is the starting point when the page is hit.
|
void |
initBinder(org.springframework.web.bind.WebDataBinder binder,
java.util.Locale locale)
Annotation that identifies methods which initialize the
WebDataBinder which will be
used for populating command and form object arguments of annotated handler methods. |
void |
initEntityValidatorBinder(org.springframework.web.bind.WebDataBinder binder,
java.util.Locale locale)
Register a validator for validation of entity using @Valid in the controller method
|
void |
populateFormWithNewEntity(javax.servlet.http.HttpServletRequest request,
org.springframework.ui.Model model)
Adds a new instance of T to the model to be used when adding a new entity T
|
java.lang.String |
prepareFormForEditEntity(ID entityID,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.springframework.ui.Model model)
Validates an entity and if validation passes adds that record.
|
void |
setDropDownFiller(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> dropDownFiller) |
void |
setDropDownValuesFor(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> values)
Adds one record to the dropDownFiller map
|
java.lang.String |
updateRecord(T entity,
org.springframework.validation.BindingResult validationResult,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Validates an entity and if validation passes adds that record.
|
protected void |
validate(ID id,
java.lang.Integer columnPosition,
java.lang.String value)
Method for adding any validations for specific or special fields.
|
public static final java.lang.String JSON
public void configureTable(TableConfiguration<T,ID> tableConfig)
configureTable in interface DataTablesController<T,ID>tableConfig - public java.util.Map<java.lang.String,java.lang.String> getDropDownValuesFor(java.lang.String key)
key - public TableConfiguration<T,ID> getTableConfig()
public java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> getDropDownFiller()
public void setDropDownFiller(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> dropDownFiller)
public void setDropDownValuesFor(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> values)
key - of the record to add to the dropDownFillervalues - a map containing "id":"value" to display in a drop down menu on the jsp pageprotected java.lang.String getJsonFormattedDropDownValues(java.util.Map<java.lang.String,java.lang.String> values)
key - protected java.lang.String getJsonFormattedDropDownValues(java.lang.String key)
@ModelAttribute
public void populateFormWithNewEntity(javax.servlet.http.HttpServletRequest request,
org.springframework.ui.Model model)
throws java.lang.InstantiationException,
java.lang.IllegalAccessException
populateFormWithNewEntity in interface DataTablesController<T,ID>model - java.lang.IllegalAccessExceptionjava.lang.InstantiationException@RequestMapping(value="/init",
method=GET)
public java.lang.String init(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.springframework.ui.Model model)
init in interface DataTablesController<T,ID>model - @RequestMapping(value="/data",
method=POST,
produces="application/json;charset=UTF-8")
@ResponseBody
public java.lang.String dashboardData(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
dashboardData in interface DataTablesController<T,ID>request - response - java.io.IOException@RequestMapping(value="/edit",
method=POST,
produces="application/json;charset=UTF-8")
@ResponseBody
public java.lang.String editRecord(@RequestParam(value="id")
ID id,
@RequestParam(value="columnPosition")
java.lang.Integer columnPosition,
@RequestParam(value="value")
java.lang.String value,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.springframework.ui.Model model)
editRecord in interface DataTablesController<T,ID>id - the primary key of the recordcolumnPosition - the column position in the tablevalue - the new value@RequestMapping(value="/prepareformedit",
method=GET,
produces="application/json;charset=UTF-8")
@ResponseBody
public java.lang.String prepareFormForEditEntity(@RequestParam(value="entityID")
ID entityID,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.springframework.ui.Model model)
prepareFormForEditEntity in interface DataTablesController<T,ID>entity - The entity to add and validateresponse - @RequestMapping(value="/postformedit",
method=POST,
produces="application/json;charset=UTF-8")
@ResponseBody
public java.lang.String editEntityUsingForm(@ModelAttribute
T entity,
@RequestParam(value="entityID")
ID entityID,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
editEntityUsingForm in interface DataTablesController<T,ID>entity - The entity to add and validateresponse - protected void validate(ID id, java.lang.Integer columnPosition, java.lang.String value) throws javax.validation.ValidationException
javax.validation.ValidationExceptionprotected java.lang.String formatValueForDisplay(ID id, java.lang.String value)
id - the id of the entity that was editedvalue - the new value@RequestMapping(value="/delete",
method=POST,
produces="application/json;charset=UTF-8")
@ResponseBody
public java.lang.String deleteRecord(@RequestParam(value="id")
ID id)
deleteRecord in interface DataTablesController<T,ID>id - the unique identifier of the record@RequestMapping(value="/add",
method=POST,
produces="application/json;charset=UTF-8")
@ResponseBody
public java.lang.String addRecord(@ModelAttribute(value="newEntity")
T entity,
org.springframework.validation.BindingResult validationResult,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
addRecord in interface DataTablesController<T,ID>entity - The entity to add and validateresponse - @RequestMapping(value="/update",
method=POST,
produces="application/json;charset=UTF-8")
@ResponseBody
public java.lang.String updateRecord(@ModelAttribute(value="newEntity")
T entity,
org.springframework.validation.BindingResult validationResult,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
updateRecord in interface DataTablesController<T,ID>entity - The entity to add and validateresponse - @InitBinder
public void initBinder(org.springframework.web.bind.WebDataBinder binder,
java.util.Locale locale)
WebDataBinder which will be
used for populating command and form object arguments of annotated handler methods.
Registers custom editors
Handles the date format from the form, using the application date format from application settings.binder - locale - @InitBinder(value="newEntity")
public void initEntityValidatorBinder(org.springframework.web.bind.WebDataBinder binder,
java.util.Locale locale)
binder - locale - public DataTablesService<T,ID> getDataTablesService()
getDataTablesService in interface DataTablesController<T,ID>public org.apache.log4j.Logger getLog()
getLog in interface DataTablesController<T,ID>public T getEntity()
getEntity in interface DataTablesController<T,ID>public java.lang.String getViewName()
getViewName in interface DataTablesController<T,ID>public java.lang.String getCustomUrl()
getCustomUrl in interface DataTablesController<T,ID>public ApplicationSettings getAppSettings()
getAppSettings in interface DataTablesController<T,ID>public java.lang.Class<T> getType()
getType in interface DataTablesController<T,ID>