Hi!
Thanks again for the consideration and for the information about the
paging and sorting listeners being called before pageBeginRender().
I did try what you proposed, but I have the same problem as before. On
first load, the table shows up as expected, but when paging or sorting,
I have the ArrayIndexOutOfBoundsException :(
Note: even if the storedDOsList property was persistent in the session,
I couldn't see it in the HttpSession section of the Tapestry exception page!
I am still using a String to define my columns, and I will try to define
them using ITableColumnModel instead (as it seemed to work for Daniel
Lydiard). Let's see where it gets me... feel free to comment, of course.
Regards,
Martin
Mind Bridge wrote:
Hi,
The reason for the problem is that the data is not provided using a
true lazy loading, but is initializated in pageBeginRender instead.
Since listeners are invoked before pageBeginRender (such as when the
table paging or sorting changes), the data is not ready yet and
problems occur.
For the time being I would suggest to ignore pageBeginRender and write
a method instead:
public List<DO> getStoredDOsList() {
List<DO> data = getDOsList();
if(data == null){
data = //get my data;
setDOsList(data);
}
return data;
}
Then change your table component to use source="ognl:storedDOsList".
Does this work?
Martin Carel wrote:
Hi Mind Bridge,
Thanks for the feedback. Here is my HTML template:
<table jwcid="[EMAIL PROTECTED]:Table" source="ognl:DOsList"
columns="carId:Car:carName, =datesColumn, =priceColumn"
rowsClass="ognl:beans.evenOdd.next" pageSize="10"
initialSortColumn="priceId">
</table>
I tried to change a couple of things, since I was stuck. Now I'm
using @Persist for my DOsList property, instead of using
persist="session" in the page specification. And now I got my data in
my session (I got the coma-separated addresses of my DO-typed objects
within squared brakets on the Tapestry exception page - normal since
this is a List object). I also now have an abstract getter for my
property, and I no more define the property per se. It looks like
this in the Java page:
@Persist
public abstract List<DO> getDOsList();
public abstract void setDOsList(List<DO> dOsList);
and it looks like this in my pageBeginRender(PageEvent event):
if(getDOsList() == null){ setDOsList(//get my data);
}
Now I'm back with the ArrayOutOfBoundsException when I click on a
page or want to sort a column. The exception refers to line 183 of
org.apache.tapestry.contrib.table.components.TablePages (see below):
170 public void changePage(IRequestCycle objCycle)
171 {
172 Object[] arrParameters =
objCycle.getListenerParameters();
173 if (arrParameters.length != 2
174 && !(arrParameters[0] instanceof ComponentAddress)
175 && !(arrParameters[1] instanceof Integer))
176 {
177 // error
178 return;
179 }
180 181 ComponentAddress objAddress =
(ComponentAddress) arrParameters[0];
182 ITableModelSource objSource = (ITableModelSource)
objAddress.findComponent(objCycle);
183 setCurrentPage(objSource, ((Integer)
arrParameters[1]).intValue());
184 185 // ensure that the change is saved
186 objSource.fireObservedStateChange();
187 }
> In addition you might want to check my answer to the recent message
"Table Model Question" from Nicholas Skriloff.
Yep, I was aware of those issues (I spent the whole day trying to
resolve my problems). Thanks for the pointer anyways.
It gets really frustrating, because this really seems like an easy
problem (ArrayOutOfBoundsException's have never given me a hard time) :(
/Martin
Mind Bridge wrote:
Hi Martin,
Is it possible to include the xml/html that define the Table
component? Without that information it is a bit hard to see what is
going on.
In addition you might want to check my answer to the recent message
"Table Model Question" from Nicholas Skriloff.
Best regards,
-mb
Martin Carel wrote:
Yes I did check those examples out. And indeed they were useful.
And I still have problems.
This morning I realized I had forgotten to put my source's data
property persistent in the session.
And bumped into another problem. Now I don't even see my table on
the first load, but have this exception:
Either the tableModel parameter or both source and columns
parameters must be specified by component
Results/resultsTable.tableView
This issue has been discussed on this mailing-list, but I couldn't
find a solution to my problem so far :(
My source is in an object called dOsList of type java.util.List.
I lazy-initialize this object in its getter method.
Thus my pageBeginRender() method is empty (the dOsList being null
on first load is handled by the getter).
I have in my page specification <property name="dOsList"
persist="session"/>
So that in my HTML template I have: source="ognl:dOsList" for my
table component.
I know (with the debugger) that my getDOsList() on my page is *not*
called. I just can't figure out why.
I can also see from the Tapestry exception page that my dOsList
property is not stored in the session.
I call it a bad day. Any thoughts?
/Martin
Daniel Lydiard wrote:
Have you tried looking at these examples yet?
https://tapestrywebcomponentexamples.dev.java.net/
(https://tapestrywebcomponentexamples.dev.java.net/files/documents/2449/8568/TapestryTables.war)
There are a lot of help...
----- Original Message ----- From: "Martin Carel"
<[EMAIL PROTECTED]>
To: "Tapestry users" <tapestry-user@jakarta.apache.org>
Sent: Thursday, February 02, 2006 1:58 AM
Subject: contrib:Table : advices requested
Hi folks!
I'm using the contrib:Table for the first time. I'm using the
source and columns parameters (and therefore not the tableModel
parameter).
My source is a List of DOs, where each DO contains some fields
(Date, double, int, etc.) with getters.
--
Q1: My table does show up as expected, with the page navigation
system. But when I'm trying to change the page, I have this error:
Failure invoking listener method 'public void
org.apache.tapestry.contrib.table.components.TablePages.changePage(org.apache.tapestry.IRequestCycle)'
on [EMAIL PROTECTED]/resultsTable.tablePages]: 1
and that's an ArrayIndexOutOfBoundsException: 1.
I have a similar error when I'm trying to sort a column. It
really does sound easy to solve, but I'm stuck.
--
Q2: I have a column which displays a price. So quite naturally
the field in my DO is a double. I want a string in front of my
double, so I figured I needed to have a column with a custom
ColumnEvaluator. Something like this:
public ITableColumn getPriceColumn() {
SimpleTableColumn priceColumn = new
SimpleTableColumn("priceId",
"Price", new PriceColumnEvaluator(), true);
return priceColumn;
}
private static class PriceColumnEvaluator implements
ITableColumnEvaluator { public Object
getColumnValue(ITableColumn objColumn, Object objRow) {
DO row = (DO) objRow;
String output = row.getCurrency() + " " + row.getPrice();
return output;
}
}
However, I suspect my price sorting does not work anymore because
now the data type for my price column is a String (since my
Evaluator returns a String). I was not comfortable with doing
this formatting thing (adding the currency sign) in my evaluator
in the first place, since it was not "pure data" stuff. Would you
have implemented it elsewhere?
Related to this, I will need another column in which I'll have to
display a little picture (which will be a link) and a few other
things. Is using a customColumnEvaluator the preferred way to do it?
Again, any hints appreciated.
/Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]