tapestry-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Amol Yadwadkar" <ayadwad...@webifyservices.com>
Subject Re: Sorting on the Date Format Treating it as Date and not as String for the table Component
Date Fri, 22 Aug 2003 05:59:55 GMT
Hi MB,
Thankx a lot for extending  all the Help!!!!
But I still have the following Questions to implement this in my Case
What I do is :-
{
populate();

ITableColumnModel objColumnModel =

new ExpressionTableColumnModel(new String[]

{"From", "from", "Message","message","Date","date"}, true);

ITableModel itable=new SimpleTableModel(tblList.toArray(), objColumnModel);

return itable;

}

populate()----will populate datas for the Bean

date---getDate() which returns Date object from Database in the regular
format "2003-06-30" (yyyy-mm-dd)

this date gets Sorted with no Issues.

Now I will like to sort this in the Customised format by using
SimpleDateFormat Class.

If  I  write "DateTableRendererSource" class which implements
ITableRendererSource then how shall I repass the customised values in

 new ExpressionTableColumnModel {"From", "from",
"Message","message","Date","date"}, true);



You have suggested  the following (may  not be completelly understood by me)
:-

ITableColumn objStartDateColumn = new ExpressionTableColumn("Start Date",
"startDate", true);
objStartDateColumn.setValueRendererSource(new
DateTableRendererSource("yyyy.MM.dd G 'at' HH:mm:ss z"));

Can I request you to please reply me on the above.

Thankx a lot for extending all the Help

Best regds,

Amol











----- Original Message -----
From: "Mind Bridge" <mindbridgeweb@yahoo.com>
To: "Tapestry users" <tapestry-user@jakarta.apache.org>
Sent: Thursday, August 21, 2003 11:08 PM
Subject: RE: Sorting on the Date Format Treating it as Date and not as
String for the table Component


> Hi Amol,
>
> There are three different items that a table column manages:
>
> a) the true value of the column entry. This is some kind of an Object, in
> your case a Date. This value is typically used in the sorting process
>
> b) the Comparator used to sort the table on this column
>
> c) the visible representation of the column value. This is what is
> displayed in the column. By default it is just toString() of the object
> described in (a), but it could be something very different, as shown in
the
> Workbench example
>
> By configuring the column object, you can manipulate these completely.
Here
> is what you could do:
>
>
> COLUMN VALUE:
> You can a standard way to get the column value from the row object, or you
> can use custom code to do that. You have the following options:
>
> a.1) [default] Use a standard column, such as ExpressionTableColumn that
> gets the column value from the row object using OGNL. This is the easiest
> approach by far:
>
> ITableColumn objMyColumn = new ExpressionTableColumn("Column Title",
"<ognl
> expression applied to the row object to get the column value>", <true if
the
> column is sortable>);
>
> Note that ExpressionTableColumn extends SimpleTableColumn, so everything
> described below applies to ExpressionTableColumn  as well.
>
>
> a.2) [the aggregation method] Use the SimpleTableColumn class to define
> your column and pass it an implementation of ITableColumnEvaluator that
> contains your custom code to extract the column value object from the row
> object. An example can be found in the Workbench example:
>
> ITableColumn objCurrencyColumn =
> new SimpleTableColumn("Currency", new CurrencyEvaluator(), true);
>
> And here is the CurrencyEvaluator class referenced above that contains the
> custom logic:
>
> private static class CurrencyEvaluator implements ITableColumnEvaluator
> {
> public Object getColumnValue(ITableColumn objColumn, Object objRow)
> {
> Locale objLocale = (Locale) objRow;
> String strCountry = objLocale.getCountry();
> if (strCountry == null || strCountry.equals(""))
> return "";
>
> DecimalFormatSymbols objSymbols = new DecimalFormatSymbols(objLocale);
> return objSymbols.getCurrencySymbol();
> }
> }
>
> The Evaluator object can be set using the setEvaluator() method as well.
>
>
> a.3) [the inheritance method] Create a subclass of SimpleTableColumn and
> override the getColumnValue() method to define your custom code to extract
> the column value object from the row object. It is somewhat simpler than
> a.2, but less flexible.
>
>
> SORTING:
> The sorting of the table is performed using a special comparator provided
> by the corresponding column.
>
> b.1) [default] The default comparator checks whether the column value
> objects implement Comparable, and if they do, that interface is used for
the
> sorting. That means that objects like String, Number, and Date are
> automatically sorted.
>
> b.2) [the aggregation method] If you would like your own comparator (e.g.
> if you want to use a Collator), you can set it in the column using
> TableColumn.setComparator(). Keep in mind that the values that the
> comparator receives are ROW objects (this is deliberate), so you might
need
> to implement a simple wrap that will extract the column value from the row
> object.
>
> b.3) [the inheritance method] You can also create your own column class
and
> override the getComparator() method to return your own Comparator.
>
>
> APPEARANCE:
> The column field is rendered using an IRender that is returned by the
> column for this particular row. You can control what this IRender is.
>
> c.1) [default] By default the column simply renders toString() of the
> column value
>
> c.2) [the aggregation method] You can implement the interface
> ITableRendererSource that returns the IRender for the given column and
row,
> and set it using the setValueRendererSource() method of SimpleTableColumn.
> Here is an example implementation that renders a Date using a particular
> format:
>
> public class DateTableRendererSource implements ITableRendererSource
> {
> private DateFormat m_objDateFormat;
>
> public DateTableRendererSource(String strDateFormat)
> {
> m_objDateFormat = new SimpleDateFormat(strDateFormat);
> }
>
> public IRender getRenderer(IRequestCycle objCycle, ITableModelSource
> objSource,
> ITableColumn objColumn, Object objRow)
> {
> SimpleTableColumn objSimpleColumn = (SimpleTableColumn) objColumn;
> Object objValue = objSimpleColumn.getColumnValue(objRow);
>
> String strAppearance = "";
> if (objValue instanceof Date)
> strAppearance = m_objDateFormat.format((Date) objValue);
>
> return new RenderString(strAppearance);
> }
> }
>
>
> And here is how it can be used:
>
> ITableColumn objStartDateColumn = new ExpressionTableColumn("Start Date",
> "startDate", true);
> objStartDateColumn.setValueRendererSource(new
> DateTableRendererSource("yyyy.MM.dd G 'at' HH:mm:ss z"));
>
>
> As you can probably notice from the Workbench example, the same approach
is
> used to define how a column should look using a Block component:
>
> Block objVerbosityBlock = (Block) getComponent("blockVerbosity");
> ITableRendererSource objVerbosityRenderer = new
> BlockTableRendererSource(objVerbosityBlock);
> objVerbosityColumn.setValueRendererSource(objVerbosityRenderer);
>
>
> c.3) [the inheritance method] You can also create your own column class
and
> override the getValueRenderer() method to return your own IRender that
will
> then be used to generate the appearance of the column.
>
>
>
> I believe that should answer you question fully. (perhaps this should go
in
> to the doc)
>
>
> In short, here is what I suggest in your case:
> - define a standard column and make sure its value is the Date object that
> you want to represent. (as described in a.1)
> - the column will be sorted properly by default (as described in b.1)
> - to make the column's appearance a custom one, use the method described
in
> c.2
>
>
> Best regards,
> - mb
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


Mime
View raw message