Sure. This code is very ugly and is backed by a List with HashMaps
inside, that's why I'm using ExpressionTableColumn instead of a
SimpleTableColumn. I'm now using source/columns, it's a lot easier...
public ITableModel getTableModel() {
ArrayList list = someMethodThatGetsTheList()
if (list == null || list.size() == 0) {
setError("The list is empty");
return null;
}
Set columns = ((HashMap)list.get(0)).keySet();
ITableColumn[] listColumns = new ITableColumn[columns.size()];
Iterator it = columns.iterator();
int i = 0;
while (it.hasNext()) {
String tmp = (String) it.next();
listColumns[i++] = new ExpressionTableColumn(tmp,tmp);
}
return new SimpleTableModel(new SimpleListTableDataModel(list),
new
SimpleTableColumnModel(listColumns));
}
I also found later that you shouldn't return a null TableModel (as I
was doing in this code when the list was empty) because the Table
component complains about it.
Hope it helps.
On 7/21/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Thanks for the reply.
>
> If I was to add rows to my list, then I haven't got separation of model from
> view. What if I also wanted to display my same model in a different table at
> the same time?
>
> I haven't been able to find an example of using a tablemodel for the values
> to back the table component. Does anyone have some code they could share?
>
> Thanks in advance,
>
> Craig
>
> -----Original Message-----
> From: Darío Vasconcelos [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, July 20, 2005 9:24 PM
> To: Tapestry users
> Subject: Re: minimum number rows in table, table value question
>
> I have used TableModel but I guess it is easier to use source/columns.
> The source can be an array or a List of a specific object, the columns
> can be as simple as a comma-separated String with the names of the
> properties (ala OGNL) that you want to display from your object.
>
> Regarding the minimum number of rows, wouldn't it be easier if you
> expanded / trimmed your List of objects to 8? I don't think there's a
> setting in contrib:Table to do such a thing...
>
> On 7/20/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> >
> >
> > Is it possible to state the minimum number of rows for a table? I would
> > some tables to always render 8 rows, regardless of how many items are in
> > my model.
> >
> >
> >
> > Also, I am having some difficulty building my value model. I have gone
> > through the tutorials, and bought the book. But, what interface/class
> > should I be looking at to supply the table values (ie TableModel in
> > swing) ? I saw ITableModel, but that does't seem to be it. For now I
> > have been using the source binding.
> >
> >
> >
> > Thanks,
> >
> >
> >
> > Craig
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
>
> --
> Communism is man's exploitation of man. Capitalism is just the opposite.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
Communism is man's exploitation of man. Capitalism is just the opposite.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]