|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.control.Column
public class Column
Provides the Column table data <td> and table header <th> renderer.
|
Table
object.
autolink
- the option to automatically render href links
for email and URL column valuesattributes
- the CSS style attributes for the table data celldataClass
- the CSS class for the table data celldataStyles
- the CSS styles for the table data celldecorator
- the custom column value rendererformat
- the MessageFormat pattern rendering
the column valueheaderClass
- the CSS class for the table header cellheaderStyles
- the CSS styles for the table header cellheaderTitle
- the table header cell value to rendersortable
- the table column sortable propertywidth
- the table cell width propertyformat
property which specifies MessageFormat
pattern
a is very useful for formatting column values. For example to render
formatted number and date values you simply specify:
Table table = new Table("table"); table.setClass("isi"); Column idColumn = new Column("purchaseId", "ID"); idColumn.setFormat("{0,number,#,###}"); table.addColumn(idColumn); Column priceColumn = new Column("purchasePrice", "Price"); priceColumn.setFormat("{0,number,currency}"); priceColumn.setTextAlign("right"); table.addColumn(priceColumn); Column dateColumn = new Column("purchaseDate", "Date"); dateColumn.setFormat("{0,date,dd MMM yyyy}"); table.addColumn(dateColumn); Column orderIdColumn = new Column("order.id", "Order ID"); table.addColumn(orderIdColumn);
Decorator
class on columns. The decorator render method is passed the table
row object and the page request Context. Using the table row you can access
all the column values enabling you to render a compound value composed of
multiple column values. For example:
Column column = new Column("email"); column.setDecorator(new Decorator() { public String render(Object row, Context context) { Person person = (Person) row; String email = person.getEmail(); String fullName = person.getFullName(); return "<a href='mailto:" + email + "'>" + fullName + "</a>"; } }); table.addColumn(column);The Context parameter of the decorator render() method enables you to render controls to provide additional functionality. For example:
public class CustomerList extends BorderedPage { private Table table = new Table("table"); private ActionLink viewLink = new ActionLink("view"); public CustomerList() { viewLink.setListener(this, "onViewClick"); viewLink.setLabel("View"); viewLink.setAttribute("title", "View customer details"); table.addControl(viewLink); table.addColumn(new Column("id")); table.addColumn(new Column("name")); table.addColumn(new Column("category")); Column column = new Column("Action"); column.setDecorator(new Decorator() { public String render(Object row, Context context) { Customer customer = (Customer) row; viewLink.setValue("" + customer.getId()); return viewLink.toString(); } }); table.addColumn(column); addControl(table); } public boolean onViewClick() { String path = getContext().getPagePath(Logout.class); setRedirect(path + "?id=" + viewLink.getValue()); return true; } }
getName() + ".headerTitle"If not found then the message will be looked up in the /click-control.properties file using the same key. If a value still cannot be found then the Column name will be converted into a header title using the method:
ClickUtils.toLabel(String)
.
Decorator
,
Table
,
Serialized FormField Summary | |
---|---|
protected Map<String,String> |
attributes
The Column attributes Map. |
protected boolean |
autolink
The automatically hyperlink column URL and email address values flag, default value is false. |
protected String |
dataClass
The column table data <td> CSS class attribute. |
protected Map<String,String> |
dataStyles
The Map of column table data <td> CSS style attributes. |
protected Decorator |
decorator
The column row decorator. |
protected boolean |
escapeHtml
The escape HTML characters flag. |
protected String |
format
The column message format pattern. |
protected String |
headerClass
The CSS class attribute of the column header. |
protected Map<String,String> |
headerStyles
The Map of column table header <th> CSS style attributes. |
protected String |
headerTitle
The title of the column header. |
protected int |
maxLength
The maximum column length. |
protected MessageFormat |
messageFormat
The optional MessageFormat used to render the column table cell value. |
protected Map<Object,Object> |
methodCache
The method cached for rendering column values. |
protected String |
name
The property name of the row object to render. |
protected Boolean |
renderId
The column render id attribute status. |
protected Boolean |
sortable
The column sortable status. |
protected Table |
table
The parent Table. |
protected String |
titleProperty
The property name used to populate the <td> "title" attribute. |
protected String |
width
The column HTML <td> width attribute. |
Constructor Summary | |
---|---|
Column()
Create a Column with no name defined. |
|
Column(String name)
Create a table column with the given property name. |
|
Column(String name,
String title)
Create a table column with the given property name and header title. |
Method Summary | |
---|---|
String |
getAttribute(String name)
Return the Column HTML attribute with the given name, or null if the attribute does not exist. |
Map<String,String> |
getAttributes()
Return the Column attributes Map. |
boolean |
getAutolink()
Return the flag to automatically render HTML hyperlinks for column URL and email addresses values. |
Comparator |
getComparator()
Return the column comparator object, which is used to sort column row values. |
String |
getDataClass()
Return the table data <td> CSS class. |
String |
getDataStyle(String name)
Return the table data <td> CSS style. |
Map<String,String> |
getDataStyles()
Return the Map of table data <td> CSS styles. |
Decorator |
getDecorator()
Return the row column <td> decorator. |
boolean |
getEscapeHtml()
Return true if the HTML characters will be escaped when rendering the column data. |
String |
getFormat()
Return the row column message format pattern. |
String |
getHeaderClass()
Return the table header <th> CSS class. |
String |
getHeaderStyle(String name)
Return the table header <th> CSS style. |
Map<String,String> |
getHeaderStyles()
Return the Map of table header <th> CSS styles. |
String |
getHeaderTitle()
Return the table header <th> title. |
String |
getId()
Return the Table and Column id appended: "table-column" Use the field the "id" attribute value if defined, or the name otherwise. |
int |
getMaxLength()
The maximum column length. |
MessageFormat |
getMessageFormat()
Return the MessageFormat instance used to format the table cell value. |
String |
getName()
Return the property name. |
Object |
getProperty(Object row)
Return the column name property value from the given row object. |
Object |
getProperty(String name,
Object row)
Return the column property value from the given row object and property name. |
boolean |
getRenderId()
Returns the column render id attribute status. |
boolean |
getSortable()
Return the column sortable status. |
Table |
getTable()
Return the parent Table containing the Column. |
String |
getTitleProperty()
Return the property name used to populate the <td> "title" attribute. |
String |
getWidth()
Return the column HTML <td> width attribute. |
boolean |
hasAttributes()
Return true if the Column has attributes or false otherwise. |
boolean |
hasDataStyles()
Return true if table data <td> CSS styles are defined. |
boolean |
hasHeaderStyles()
Return true if table header <th> CSS styles are defined. |
protected boolean |
renderLink(Object value,
HtmlStringBuffer buffer)
Render the given table cell value to the buffer as a mailto: or http: hyperlink, or as an ordinary string if the value is determined not be linkable. |
void |
renderTableData(Object row,
HtmlStringBuffer buffer,
Context context,
int rowIndex)
Render the column table data <td> element to the given buffer using the passed row object. |
protected void |
renderTableDataContent(Object row,
HtmlStringBuffer buffer,
Context context,
int rowIndex)
Render the content within the column table data <td> element. |
void |
renderTableHeader(HtmlStringBuffer buffer,
Context context)
Render the column table header <tr> element to the given buffer. |
void |
setAttribute(String name,
String value)
Set the Column with the given HTML attribute name and value. |
void |
setAutolink(boolean autolink)
Set the flag to automatically render HTML hyperlinks for column URL and email addresses values. |
void |
setComparator(Comparator comparator)
Set the column comparator object, which is used to sort column row values. |
void |
setDataClass(String dataClass)
Set the table data <td> CSS class. |
void |
setDataStyle(String name,
String value)
Set the table data <td> CSS style name and value pair. |
void |
setDecorator(Decorator decorator)
Set the row column <td> decorator. |
void |
setEscapeHtml(boolean escape)
Set the escape HTML characters when rendering column data flag. |
void |
setFormat(String pattern)
Set the row column message format pattern. |
void |
setHeaderClass(String headerClass)
Set the table header <th> CSS class. |
void |
setHeaderStyle(String name,
String value)
Set the table header <th> CSS style name and value pair. |
void |
setHeaderTitle(String title)
Set the table header <th> title. |
void |
setMaxLength(int value)
Set the maximum column length. |
void |
setMessageFormat(MessageFormat messageFormat)
Set the MessageFormat instance used to format the table cell value. |
void |
setName(String name)
Set the property name. |
void |
setRenderId(boolean value)
Set the column render id attribute status. |
void |
setSortable(boolean value)
Set the column sortable status. |
void |
setTable(Table table)
Set the Column's the parent Table. |
void |
setTextAlign(String align)
Set the column CSS "text-align" style for the header <th> and data <td> elements. |
void |
setTitleProperty(String property)
Set the property name used to populate the <td> "title" attribute. |
void |
setVerticalAlign(String align)
Set the column CSS "vertical-align" style for the header <th> and data <td> elements. |
void |
setWidth(String value)
Set the column HTML <td> width attribute. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Map<String,String> attributes
protected boolean autolink
protected String dataClass
protected Map<String,String> dataStyles
protected Decorator decorator
protected boolean escapeHtml
protected String format
protected String headerClass
protected Map<String,String> headerStyles
protected String headerTitle
protected int maxLength
protected MessageFormat messageFormat
protected String name
protected Boolean renderId
protected transient Map<Object,Object> methodCache
protected Boolean sortable
protected Table table
protected String titleProperty
protected String width
Constructor Detail |
---|
public Column(String name)
name
- the name of the property to renderpublic Column(String name, String title)
name
- the name of the property to rendertitle
- the column header title to renderpublic Column()
Method Detail |
---|
public String getAttribute(String name)
name
- the name of column HTML attribute
public void setAttribute(String name, String value)
name
- the name of the column HTML attributevalue
- the value of the column HTML attribute
IllegalArgumentException
- if attribute name is nullpublic Map<String,String> getAttributes()
public boolean hasAttributes()
public boolean getAutolink()
public void setAutolink(boolean autolink)
autolink
- the flag to automatically hyperlink column URL and
email addresses flagpublic Comparator getComparator()
public void setComparator(Comparator comparator)
comparator
- the column row data sorting comparator objectpublic String getDataClass()
public void setDataClass(String dataClass)
dataClass
- the table data CSS classpublic String getDataStyle(String name)
name
- the CSS style name
public void setDataStyle(String name, String value)
name
- the CSS style namevalue
- the CSS style valuepublic boolean hasDataStyles()
public Map<String,String> getDataStyles()
public Decorator getDecorator()
public void setDecorator(Decorator decorator)
decorator
- the row column <td> decoratorpublic boolean getEscapeHtml()
public void setEscapeHtml(boolean escape)
escape
- the flag to escape HTML characterspublic String getFormat()
public void setFormat(String pattern)
Column idColumn = new Column("purchaseId", "ID"); idColumn.setFormat("{0,number,#,###}"); Column priceColumn = new Column("purchasePrice", "Price"); priceColumn.setFormat("{0,number,currency}"); Column dateColumn = new Column("purchaseDate", "Date"); dateColumn.setFormat("{0,date,dd MMM yyyy}");
Format Type | Format Style | Subformat Created |
---|---|---|
number
| (none) | NumberFormat.getInstance(getLocale())
|
integer
| NumberFormat.getIntegerInstance(getLocale())
| |
currency
| NumberFormat.getCurrencyInstance(getLocale())
| |
percent
| NumberFormat.getPercentInstance(getLocale())
| |
SubformatPattern | new DecimalFormat(subformatPattern, new DecimalFormatSymbols(getLocale()))
| |
date
| (none) | DateFormat.getDateInstance(DateFormat.DEFAULT, getLocale())
|
short
| DateFormat.getDateInstance(DateFormat.SHORT, getLocale())
| |
medium
| DateFormat.getDateInstance(DateFormat.DEFAULT, getLocale())
| |
long
| DateFormat.getDateInstance(DateFormat.LONG, getLocale())
| |
full
| DateFormat.getDateInstance(DateFormat.FULL, getLocale())
| |
SubformatPattern | new SimpleDateFormat(subformatPattern, getLocale())
| |
time
| (none) | DateFormat.getTimeInstance(DateFormat.DEFAULT, getLocale())
|
short
| DateFormat.getTimeInstance(DateFormat.SHORT, getLocale())
| |
medium
| DateFormat.getTimeInstance(DateFormat.DEFAULT, getLocale())
| |
long
| DateFormat.getTimeInstance(DateFormat.LONG, getLocale())
| |
full
| DateFormat.getTimeInstance(DateFormat.FULL, getLocale())
| |
SubformatPattern | new SimpleDateFormat(subformatPattern, getLocale())
| |
choice
| SubformatPattern | new ChoiceFormat(subformatPattern)
|
Symbol | Location | Localized? | Meaning |
---|---|---|---|
0
| Number | Yes | Digit |
#
| Number | Yes | Digit, zero shows as absent |
.
| Number | Yes | Decimal separator or monetary decimal separator |
-
| Number | Yes | Minus sign |
,
| Number | Yes | Grouping separator |
E
| Number | Yes | Separates mantissa and exponent in scientific notation. Need not be quoted in prefix or suffix. |
;
| Subpattern boundary | Yes | Separates positive and negative subpatterns |
%
| Prefix or suffix | Yes | Multiply by 100 and show as percentage |
\u2030
| Prefix or suffix | Yes | Multiply by 1000 and show as per mille |
¤ (\u00A4 )
| Prefix or suffix | No | Currency sign, replaced by currency symbol. If doubled, replaced by international currency symbol. If present in a pattern, the monetary decimal separator is used instead of the decimal separator. |
'
| Prefix or suffix | No | Used to quote special characters in a prefix or suffix,
for example, "'#'#" formats 123 to
"#123" . To create a single quote
itself, use two in a row: "# o''clock" .
|
Letter | Date or Time Component | Presentation | Examples |
---|---|---|---|
G
| Era designator | Text | AD
|
y
| Year | Year | 1996 ; 96
|
M
| Month in year | Month | July ; Jul ; 07
|
w
| Week in year | Number | 27
|
W
| Week in month | Number | 2
|
D
| Day in year | Number | 189
|
d
| Day in month | Number | 10
|
F
| Day of week in month | Number | 2
|
E
| Day in week | Text | Tuesday ; Tue
|
a
| Am/pm marker | Text | PM
|
H
| Hour in day (0-23) | Number | 0
|
k
| Hour in day (1-24) | Number | 24
|
K
| Hour in am/pm (0-11) | Number | 0
|
h
| Hour in am/pm (1-12) | Number | 12
|
m
| Minute in hour | Number | 30
|
s
| Second in minute | Number | 55
|
S
| Millisecond | Number | 978
|
z
| Time zone | General time zone | Pacific Standard Time ; PST ; GMT-08:00
|
Z
| Time zone | RFC 822 time zone | -0800
|
pattern
- the message format patternpublic int getMaxLength()
public void setMaxLength(int value)
value
- the maximum column lengthpublic MessageFormat getMessageFormat()
public void setMessageFormat(MessageFormat messageFormat)
messageFormat
- the MessageFormat used to format the table cell
valuepublic String getName()
public void setName(String name)
name
- the property name to setpublic String getHeaderClass()
public void setHeaderClass(String headerClass)
headerClass
- the table header CSS classpublic String getHeaderStyle(String name)
name
- the CSS style name
public void setHeaderStyle(String name, String value)
name
- the CSS style namevalue
- the CSS style valuepublic boolean hasHeaderStyles()
public Map<String,String> getHeaderStyles()
public String getHeaderTitle()
getName() + ".headerTitle"If not found then the message will be looked up in the /click-control.properties file using the same key. If a value still cannot be found then the Column name will be converted into a header title using the method:
ClickUtils.toLabel(String)
public void setHeaderTitle(String title)
title
- the table header titlepublic String getId()
public boolean getSortable()
Table.sortable
property.
public void setRenderId(boolean value)
value
- set the column render id attribute statuspublic boolean getRenderId()
Table.renderId
property.
public void setSortable(boolean value)
value
- the column sortable statuspublic Table getTable()
public void setTable(Table table)
table
- Column's parent Tablepublic void setTextAlign(String align)
align
- the CSS "text-align" value: [left, right, center]public String getTitleProperty()
public void setTitleProperty(String property)
property
- the property name used to populate the <td> "title" attributepublic void setVerticalAlign(String align)
align
- the CSS "vertical-align" valuepublic String getWidth()
public void setWidth(String value)
value
- the column HTML <td> width attributepublic void renderTableData(Object row, HtmlStringBuffer buffer, Context context, int rowIndex)
row
- the row object to renderbuffer
- the string buffer to render tocontext
- the request contextrowIndex
- the index of the current row within the parent tablepublic void renderTableHeader(HtmlStringBuffer buffer, Context context)
buffer
- the string buffer to render tocontext
- the request contextpublic Object getProperty(Object row)
row
- the row object to obtain the property from
RuntimeException
- if an error occurred obtaining the propertypublic Object getProperty(String name, Object row)
name
- the name of the propertyrow
- the row object to obtain the property from
RuntimeException
- if an error occurred obtaining the propertyprotected void renderTableDataContent(Object row, HtmlStringBuffer buffer, Context context, int rowIndex)
row
- the row object to renderbuffer
- the string buffer to render tocontext
- the request contextrowIndex
- the index of the current row within the parent tableprotected boolean renderLink(Object value, HtmlStringBuffer buffer)
value
- the table cell value to renderbuffer
- the StringBuffer to render to
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |