You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andreas Pardeike <an...@pardeike.net> on 2004/11/09 16:28:54 UTC

Help with IBasicTableModel

Hi,

I am stuck with my first real table. I need to pull (potentially
large data) out of a database and want to implement a IBasicTableModel.

So far, I have

package Fsys.Models;
public class Artikel implements Serializable
{
	private String nummer;
	private String title;
	
	public Artikel(String theNummer, String theTitle)
	{	
		nummer = theNummer;
		title = theTitle;
	}
	
	public String getArtikelNummer()
	{
		return nummer;
	}
	
	public String getTitle()
	{
		return title;
	}
}

package Fsys.Models;
public class ArtikelTable implements IBasicTableModel
{
	public int getRowCount()
	{
		return 20;
	}
	
	public Iterator getCurrentPageRows(int firstRow, int rowsPerPage, 
ITableColumn sortColumn, boolean sortOrder)
	{
		// simulate data - ultimately, I will use cayenne here

		List result = new ArrayList();

		result.add(new Artikel("3674574555", "test stuff 1"));
		result.add(new Artikel("8573523544", "more crap 1"));
		result.add(new Artikel("5934535354", "Andreas 1"));
		result.add(new Artikel("5673453454", "Pardeike 1"));
		result.add(new Artikel("2634235233", "Tapestry 1"));
		result.add(new Artikel("7656744525", "test stuff 2"));
		result.add(new Artikel("6735562525", "more crap 2"));
		result.add(new Artikel("7845634523", "Andreas 2"));
		result.add(new Artikel("1534645766", "Pardeike 2"));
		result.add(new Artikel("4575674634", "Tapestry 2"));
		
		return result.iterator();
	}
}

and

<table jwcid="table@contrib:Table"
	source="ognl:Fsys.Models.ArtikelTable"
	columns="ArtikelNummer, Title"
	pageSize="10"
	pagesDisplayed="5"/>

but it does not work. How do I specify source="" to use my custom
implementation? I think it needs an Object but I tried that too
without success.

Is this the best way to tie a table to a sql data souce (preferable
cayenne). Any help and basic code sketches welcome,

Andreas Pardeike


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Help with IBasicTableModel

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Nov 9, 2004, at 10:28 AM, Andreas Pardeike wrote:
> <table jwcid="table@contrib:Table"
> 	source="ognl:Fsys.Models.ArtikelTable"
> 	columns="ArtikelNummer, Title"
> 	pageSize="10"
> 	pagesDisplayed="5"/>
>
> but it does not work. How do I specify source="" to use my custom
> implementation? I think it needs an Object but I tried that too
> without success.

Try source="ognl:new Fsys.Models.ArtikelTable()".   You need to have an 
instance of the table model, not just the class.

What error are you getting?

> Is this the best way to tie a table to a sql data souce (preferable
> cayenne). Any help and basic code sketches welcome,

This is a fine way to do this.  I implemented the same sort of thing on 
my last project, pulling data from the database indirectly through 
session bean calls.  Consider caching the count - you'll notice that 
the methods in that IBasicTableModel are called more than you might 
initially think during a request cycle.

	Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Help with IBasicTableModel

Posted by Andreas Pardeike <an...@pardeike.net>.
On 10 nov 2004, at 14.49, Bryan Lewis wrote:

> (Yes, a bit off-topic, but anyway...)   Check out Cayenne's paged 
> queries.
> Try, for example, "query.setPageSize(n);".  Cayenne will do the minimal
> amount of fetching and object-packaging to deliver the first n rows.
> According to the docs at
> http://objectstyle.org/cayenne/userguide/perform/paged-queries.html:  
> "For
> the rest of the result set, only primary keys are read."

Thanks. That seems to work fine.

> Disclaimer:  I haven't used the Table component so I don't know how 
> well
> this suggestion will mesh with that.  It works well with my simple
> home-grown list-paging component.

Here's where my problem still remains. I am not clear on the overall 
concept
of contrib:Table. The questions I have are:

- where do I actually create the query result? I want this to be cached 
and
   I need to recache it when i.e. the sort order changes (because I 
don't sort
   in memory)

- must I use the more complex models or is IBasicTableModel sufficient 
for
   my needs?

- should I switch to a row centric model so that cayenne is simply 
called for
   every row (and thus the paging inside cayenne can do its magic? Right 
now,
   I have put all my query code inside an implementation of 
IBasicTableModel
   and it seems unnecessary much code to handle all the states. Plus I 
am forced
   to calculate the current rows by extracting them from my cached 
result by
   running a for loop through n -> n + rowsPerPage which is tricky at 
the last
   page where there may be less rows than rowsPerPage...

Andreas Pardeike 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Help with IBasicTableModel

Posted by Bryan Lewis <br...@maine.rr.com>.
(Yes, a bit off-topic, but anyway...)   Check out Cayenne's paged queries.
Try, for example, "query.setPageSize(n);".  Cayenne will do the minimal
amount of fetching and object-packaging to deliver the first n rows.
According to the docs at
http://objectstyle.org/cayenne/userguide/perform/paged-queries.html:  "For
the rest of the result set, only primary keys are read."

Disclaimer:  I haven't used the Table component so I don't know how well
this suggestion will mesh with that.  It works well with my simple
home-grown list-paging component.


----- Original Message ----- 
From: "Andreas Pardeike" <an...@pardeike.net>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Wednesday, November 10, 2004 8:04 AM
Subject: Re: Help with IBasicTableModel


> On 9 nov 2004, at 19.52, Erik Hatcher wrote:
>
> > Don't fret - you're in the right place on this list.  Don't be afraid
> > to ask.  And if you have suggestions for documentation improvement, or
> > perhaps want to volunteer to help clear things up, let us know.   The
> > main issue is that once someone understands something previously
> > misunderstood, it is of little importance to go back and document it
> > for himself/herself - it is now known!
>
> Thanks! And here I go with another officially stuck question:
>
> How do I deliver only i.e. 'n' rows to the table component with an
> offset of 'm' rows from within my result set.
>
> I would like to use cayenne together with DB2 (which does not support
> LIMIT n, m) and my result sets are quite large. I know that this
> question
> is a bit off-topic but since I would need to combine this with the
> table component I thought I give it a try.
>
> I would need a general strategy on where to feed the search parameters
> and when to run the query (once for a total set or every time for just
> the rows displayed on the current page). What I've tried so far is to
> fetch a full result into a List and then use subList.iterator() as the
> result of getCurrentPageRows - that gives me a OutOfMemory exception ...
>
> BTW: I now use source="new Fsys.Models.ArtikelTable(getVisit())" in
> order
> to have my visit object provide the datacontext for cayenne. Works fine!
>
> Sorry for being too vague here but I am still at the beginning of
> putting
> together all the bits and pieces.
>
> Andreas Pardeike
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Help with IBasicTableModel

Posted by Andreas Pardeike <an...@pardeike.net>.
On 9 nov 2004, at 19.52, Erik Hatcher wrote:

> Don't fret - you're in the right place on this list.  Don't be afraid 
> to ask.  And if you have suggestions for documentation improvement, or 
> perhaps want to volunteer to help clear things up, let us know.   The 
> main issue is that once someone understands something previously 
> misunderstood, it is of little importance to go back and document it 
> for himself/herself - it is now known!

Thanks! And here I go with another officially stuck question:

How do I deliver only i.e. 'n' rows to the table component with an
offset of 'm' rows from within my result set.

I would like to use cayenne together with DB2 (which does not support
LIMIT n, m) and my result sets are quite large. I know that this 
question
is a bit off-topic but since I would need to combine this with the
table component I thought I give it a try.

I would need a general strategy on where to feed the search parameters
and when to run the query (once for a total set or every time for just
the rows displayed on the current page). What I've tried so far is to
fetch a full result into a List and then use subList.iterator() as the
result of getCurrentPageRows - that gives me a OutOfMemory exception ...

BTW: I now use source="new Fsys.Models.ArtikelTable(getVisit())" in 
order
to have my visit object provide the datacontext for cayenne. Works fine!

Sorry for being too vague here but I am still at the beginning of 
putting
together all the bits and pieces.

Andreas Pardeike


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Help with IBasicTableModel

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Nov 9, 2004, at 11:40 AM, Andreas Pardeike wrote:
> Excellent. That solved it. To be honest, Tapestry documentation  
> (especially
> contrib:Table) to be sporadic. But how to use ognl in the non-trivial  
> cases
> (like here, to be able to use "new class()" ) is basically  
> non-documented.

This is a fair complaint, but its also a very difficult one to tackle.   
In this particular case, the expression is purely OGNL and has nothing  
whatsoever to do with Tapestry.  You'd certainly find the 'new class()'  
construct in the OGNL documentation.  In fact, it is documented here:

	http://www.ognl.org/2.6.7/Documentation/html/LanguageGuide/ 
constructors.html

> The docs say 'Object' but I tried many ways to pass an object - without
> success. Is there any additional information on the different use  
> cases of
> ognl within a tapestry context?

There is nothing special about the OGNL expressions - so pure OGNL  
documentation is applicable.  The only oddities come from escaping  
within XML specifications or using double and single quotes in HTML  
templates to keep things parsable.  All OGNL expressions are relative  
to their containing component, which is useful to know what objects are  
available to start with (like visit, global, page, etc).

> :-(

Don't fret - you're in the right place on this list.  Don't be afraid  
to ask.  And if you have suggestions for documentation improvement, or  
perhaps want to volunteer to help clear things up, let us know.   The  
main issue is that once someone understands something previously  
misunderstood, it is of little importance to go back and document it  
for himself/herself - it is now known!

	Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Help with IBasicTableModel

Posted by Andreas Pardeike <an...@pardeike.net>.
On 9 nov 2004, at 17.04, Erik Hatcher wrote:

> On Nov 9, 2004, at 10:28 AM, Andreas Pardeike wrote:
>> <table jwcid="table@contrib:Table"
>> 	source="ognl:Fsys.Models.ArtikelTable"
>> 	columns="ArtikelNummer, Title"
>> 	pageSize="10"
>> 	pagesDisplayed="5"/>
>>
>> but it does not work. How do I specify source="" to use my custom
>> implementation? I think it needs an Object but I tried that too
>> without success.
>
> Try source="ognl:new Fsys.Models.ArtikelTable()".   You need to have 
> an instance of the table model, not just the class.

Excellent. That solved it. To be honest, Tapestry documentation 
(especially
contrib:Table) to be sporadic. But how to use ognl in the non-trivial 
cases
(like here, to be able to use "new class()" ) is basically 
non-documented.
The docs say 'Object' but I tried many ways to pass an object - without
success. Is there any additional information on the different use cases 
of
ognl within a tapestry context?

:-(

On 9 nov 2004, at 17.13, Jamie Orchard-Hays wrote:

> Have you got it working without implementing your own table model 
> first?

Yes, from what I can read from the docs, you don't need a table model if
the defaults work for you (they don't work for me but it's a good 
start).

Andreas Pardeike


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Help with IBasicTableModel

Posted by Jamie Orchard-Hays <ja...@dang.com>.
Have you got it working without implementing your own table model first?


----- Original Message ----- 
From: "Andreas Pardeike" <an...@pardeike.net>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Tuesday, November 09, 2004 10:28 AM
Subject: Help with IBasicTableModel


> Hi,
> 
> I am stuck with my first real table. I need to pull (potentially
> large data) out of a database and want to implement a IBasicTableModel.
> 
> So far, I have
> 
> package Fsys.Models;
> public class Artikel implements Serializable
> {
> private String nummer;
> private String title;
> 
> public Artikel(String theNummer, String theTitle)
> { 
> nummer = theNummer;
> title = theTitle;
> }
> 
> public String getArtikelNummer()
> {
> return nummer;
> }
> 
> public String getTitle()
> {
> return title;
> }
> }
> 
> package Fsys.Models;
> public class ArtikelTable implements IBasicTableModel
> {
> public int getRowCount()
> {
> return 20;
> }
> 
> public Iterator getCurrentPageRows(int firstRow, int rowsPerPage, 
> ITableColumn sortColumn, boolean sortOrder)
> {
> // simulate data - ultimately, I will use cayenne here
> 
> List result = new ArrayList();
> 
> result.add(new Artikel("3674574555", "test stuff 1"));
> result.add(new Artikel("8573523544", "more crap 1"));
> result.add(new Artikel("5934535354", "Andreas 1"));
> result.add(new Artikel("5673453454", "Pardeike 1"));
> result.add(new Artikel("2634235233", "Tapestry 1"));
> result.add(new Artikel("7656744525", "test stuff 2"));
> result.add(new Artikel("6735562525", "more crap 2"));
> result.add(new Artikel("7845634523", "Andreas 2"));
> result.add(new Artikel("1534645766", "Pardeike 2"));
> result.add(new Artikel("4575674634", "Tapestry 2"));
> 
> return result.iterator();
> }
> }
> 
> and
> 
> <table jwcid="table@contrib:Table"
> source="ognl:Fsys.Models.ArtikelTable"
> columns="ArtikelNummer, Title"
> pageSize="10"
> pagesDisplayed="5"/>
> 
> but it does not work. How do I specify source="" to use my custom
> implementation? I think it needs an Object but I tried that too
> without success.
> 
> Is this the best way to tie a table to a sql data souce (preferable
> cayenne). Any help and basic code sketches welcome,
> 
> Andreas Pardeike
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org