|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.control.AbstractControl org.apache.click.control.Table org.apache.click.extras.control.FormTable
public class FormTable
Provides a FormTable data grid control.
form
object
and an array of FieldColumn
objects.
Please note it is possible to associate FormTable with an external
Form through this constructor
.
FieldColumn extends the Column
class and includes a Field
object which is uses to render its column value. Each table data cell
≶td> contains a uniquely named form field, which is rendered
by the columns field.
When the tables form field data is posted the submitted values are processed
by the column field objects using a flyweight style visitor pattern, i.e.
the column field instance is reused and processes all the posted values for
its column.
After FormTable changes have been submitted their values will be applied to
the objects contained in the Tables rows list. If the posted values are
invalid for the given field constraints, the field error will be highlighted
in the table. Field error messages will be rendered as 'title' attribute
tooltip values.
public class FormTablePage extends BorderPage { private static final int NUM_ROWS = 5; public FormTable table = new FormTable(); public FormTablePage() { // Setup customers table table.addStyleClass("simple"); table.setAttribute("width", "550px"); table.getForm().setButtonAlign(Form.ALIGN_RIGHT); table.addColumn(new Column("id")); FieldColumn column = new FieldColumn("name", new TextField()); column.getField().setRequired(true); table.addColumn(column); column = new FieldColumn("investments", new InvestmentSelect()); column.getField().setRequired(true); table.addColumn(column); column = new FieldColumn("holdings", new NumberField()); column.setAttribute("style", "{text-align:right;}"); table.addColumn(column); column = new FieldColumn("active", new Checkbox()); column.setAttribute("style", "{text-align:center;}"); table.addColumn(column); table.getForm().add(new Submit("ok", " OK ", this, "onOkClick")); table.getForm().add(new Submit("cancel", this, "onCancelClick")); } public void onInit() { // Populate table before it is processed List customers = getCustomerService().getCustomersSortedByName(NUM_ROWS); table.setRowList(customers); } public boolean onOkClick() { if (table.getForm().isValid()) { getDataContext().commitChanges(); } return true; } public boolean onCancelClick() { getDataContext().rollbackChanges(); List customers = getCustomerService().getCustomersSortedByName(NUM_ROWS); table.setRowList(customers); table.setRenderSubmittedValues(false); return true; } }Note in this example the onCancelClick() button rolls back the changes made to the rowList objects, by reloading their values from the database and having the FormTable not render the submitted values.
constructor
which accepts a Form.
Example usage:
private Form form; private FormTable formTable; public void onInit() { // LIMITATION: Form only processes its children when the Form is submitted. // Since FormTable sorting and paging is done via GET requests, // the Form onProcess method won't process the FormTable. // To fix this we override the default Form#onProcess behavior and check // if Form was submitted. If it was not we explicitly process the FormTable. form = new Form("form") { public boolean onProcess() { if (isFormSubmission()) { // Delegate to super implementation return super.onProcess(); } else { // If form is not submitted, explicitly process the table return formTable.onProcess(); } } }; formTable = new FormTable("formTable", form); formTable.setPageSize(10); form.add(formTable); ... }
FieldColumn
,
Form
,
Table
,
Serialized FormField Summary | |
---|---|
protected Form |
form
The table form. |
protected boolean |
renderSubmittedValues
The render the posted form values flag, default value is true. |
protected boolean |
useInternalForm
Indicates whether an internal Form should be created, true by default. |
Fields inherited from class org.apache.click.control.Table |
---|
ASCENDING, bannerPosition, caption, CLASS_BLUE1, CLASS_BLUE2, CLASS_COMPLEX, CLASS_ISI, CLASS_ITS, CLASS_MARS, CLASS_NOCOL, CLASS_ORANGE1, CLASS_ORANGE2, CLASS_REPORT, CLASS_SIMPLE, CLASS_STYLES, COLUMN, columnList, columns, controlLink, controlList, dataProvider, height, hoverRows, nullifyRowListOnDestroy, PAGE, pageNumber, pageSize, paginator, PAGINATOR_ATTACHED, PAGINATOR_DETACHED, PAGINATOR_INLINE, paginatorAttachment, POSITION_BOTH, POSITION_BOTTOM, POSITION_TOP, renderId, rowCount, rowList, showBanner, SORT, sortable, sorted, sortedAscending, sortedColumn, width |
Fields inherited from class org.apache.click.control.AbstractControl |
---|
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles |
Fields inherited from interface org.apache.click.Control |
---|
CONTROL_MESSAGES |
Constructor Summary | |
---|---|
FormTable()
Create a FormTable with no name defined. |
|
FormTable(String name)
Create a FormTable for the given name. |
|
FormTable(String name,
Form form)
Create an FormTable for the given name and Form. |
Method Summary | |
---|---|
Column |
addColumn(Column column)
Add the column to the table. |
String |
getButtonsHtml()
Return the form buttons HTML string representation. |
int |
getControlSizeEst()
|
Form |
getForm()
Return the form object associated with this FormTable. |
List<Element> |
getHeadElements()
Return the HEAD elements for the Control. |
boolean |
getRenderSubmittedValues()
Return true if the table will render the submitted form values. |
boolean |
onProcess()
Process the FormTable control. |
void |
render(HtmlStringBuffer buffer)
Render the HTML representation of the FormTable. |
protected void |
renderButtons(HtmlStringBuffer buffer)
Render the Form Buttons to the string buffer. |
void |
setName(String name)
|
void |
setPageNumber(int pageNumber)
|
void |
setParent(Object parent)
Set the parent of the FormTable. |
void |
setRenderSubmittedValues(boolean render)
Set whether the table should render the submitted form values. |
void |
setRowList(List rowList)
Set the list of form table rows. |
void |
setSortedAscending(boolean ascending)
|
void |
setSortedColumn(String columnName)
|
Methods inherited from class org.apache.click.control.AbstractControl |
---|
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getHtmlImports, getId, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, removeBehavior, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setListener, setStyle, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Form form
protected boolean useInternalForm
protected boolean renderSubmittedValues
Constructor Detail |
---|
public FormTable(String name, Form form)
name
- the table nameform
- the table form
IllegalArgumentException
- if the name is nullpublic FormTable(String name)
name
- the table name
IllegalArgumentException
- if the name is nullpublic FormTable()
Method Detail |
---|
public String getButtonsHtml()
public Column addColumn(Column column)
Table.columns
Map using its name.
addColumn
in class Table
column
- the column to add to the table
IllegalArgumentException
- if the table already contains a column
with the same nameTable.addColumn(Column)
public Form getForm()
contructor
.
public List<Element> getHeadElements()
getHeadElements
in interface Control
getHeadElements
in class Table
Control.getHeadElements()
public void setName(String name)
setName
in interface Control
setName
in class Table
name
- of the control
IllegalArgumentException
- if the name is nullControl.setName(String)
public void setParent(Object parent)
Table.getControlLink()
to the getForm()
.
setParent
in interface Control
setParent
in class Table
parent
- the parent of the FormTable
IllegalStateException
- if AbstractControl.name
is not defined
IllegalArgumentException
- if the given parent instance is
referencing this object: if (parent == this)Control.setParent(Object)
public boolean getRenderSubmittedValues()
public void setRenderSubmittedValues(boolean render)
render
- set whether the table should render the submitted form valuespublic void setRowList(List rowList)
Table.onDestroy()
method
at the end of each request.
setRowList
in class Table
rowList
- the list of table rows to setpublic void setSortedColumn(String columnName)
setSortedColumn
in class Table
columnName
- the name of the sorted columnTable.setSortedColumn(java.lang.String)
public void setSortedAscending(boolean ascending)
setSortedAscending
in class Table
ascending
- the ascending sort order statusTable.setSortedAscending(boolean)
public void setPageNumber(int pageNumber)
setPageNumber
in class Table
pageNumber
- set the currently displayed page numberTable.setPageNumber(int)
public boolean onProcess()
onProcess
in interface Control
onProcess
in class Table
Table.onProcess()
public int getControlSizeEst()
getControlSizeEst
in class Table
AbstractControl.getControlSizeEst()
public void render(HtmlStringBuffer buffer)
render
in interface Control
render
in class Table
buffer
- the specified buffer to render the control's output toAbstractControl.toString()
protected void renderButtons(HtmlStringBuffer buffer)
buffer
- the StringBuffer to render to
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |