Hi,

The reason is that the OGNL expressions are evaluated against the row object when sorting, but the expressions in the Block are evaluated against the page/component in which that block resides (this is to be expected as Block is a generic component).

Thus, I am guessing that you have a Block that uses the 'lastPurchase' expression, but without the prefix 'components.membersTableView.tableRow' that ensures that the expression is evaluated against the row object rather than the page.


There are several options to avoid that problem:

1) In all cases in the Blocks where an expression has to be evaluated against the row object, preprend it with 'components.membersTableView.tableRow'. For example, 'lastPurchase' should become 'components.membersTableView.tableRow.lastPurchase'

2) Make a shortcut -- define a 'row' property in your page by adding the following to your .page file
   <property name="row"/>

and then have the table store the current row object in it by adding the following line:
   <component id="membersTableFormRows" type="contrib:TableRows">
       <binding name="row" value="row"/>
   </component>

The above expression can then become:
   row.lastPurchase

In addition, the blocks that I wrote about also become shorter:

<span jwcid="[EMAIL PROTECTED]">
   <span jwcid="@Insert" value="row.formatDate(row.lastDate)"/>
</span>

etc...

I would suggest (2) as that would make the code much cleaner.

I hope that helps...
-mb


Joe Goldwasser wrote:

Mind Bridge - Thanks for you reply.

I updated my code to the follow the pattern you outlined.

I'm getting an "ognl.NoSuchPropertyException" when it tries to load the
columns.  It shows "$SegmentDetail_14.lastPurchase" with the error...
SegmentDetail is my page, the lastPurchase should be coming from the items
in the "members" list from the page, not the page directly.

It seems to be trying to load the column from my page, instead of the from
the source (ie, <binding name="source" value="ognl:members" />)

Any ideas?  I wonder if it's related to the fact that I'm using this in a
page and not a component.
Thanks,

Joe



-----Original Message-----
From: Mind Bridge [mailto:[EMAIL PROTECTED] Sent: Friday, July 22, 2005 6:20 PM
To: Tapestry users
Subject: Re: Tapestry4 contrib:Table format & sort

Hi,

The below explanation is also related to another message that appeared on
the list a bit earlier.
It is important to remember the below principle when working with
contrib:Table (and I am making a point to emphasize it in the docs).

There are two distinct aspects of a table column:

- The first one is the value used for sorting. This is the OGNL expression
given in the 'columns' string.

- The second one is the visual representation of the column. By default that
is simply the string representation of the value used for sorting, as the
two often coincide. Nevertheless, it is possible to define a more elaborate
representation by declaring a Block with a name <column_id>ColumnValue.


To apply those principles, here is how I would approach what you want to do:

In the .page/.jwc:

     <binding name="columns">
          accountNumber, firstName, lastPurchase:amount, visitCnt, lastDate
     </binding>


In the .html:

<span jwcid="[EMAIL PROTECTED]">
   $<span jwcid="@Insert"
value="formatCurrency(components.membersTableView.tableRow.amount)"/>
</span>

<span jwcid="[EMAIL PROTECTED]">
   <span jwcid="@Insert"
value="formatNumber(components.membersTableView.tableRow.visitCnt)"/>
</span>

<span jwcid="[EMAIL PROTECTED]">
   <span jwcid="@Insert"
value="formatDate(components.membersTableView.tableRow.lastDate)"/>
</span>


In .properties:

accountNumber=Account Number
firstName=First Name
lastPurchase=Last Avg Purchase
visitCnt=Number Visits
lastDate=Last Date


In that way the columns will be sorted properly, there is more freedom to
make them look like it is needed, and column titles can contain random
symbols and are internationalizable.

Please note that the code has not been tested and may contain bugs here and
there -- best to just extract the principles from it. There are other less
verbose ways to do the above (e.g. with a 'row' property), but that is an
optimization.

-mb


Joe Goldwasser wrote:

I'm trying to get the contrib:table to format my data (date, currency, numbers, etc) then be able to sort it.

I'm using Tapestry 4 beta 2.

I'm able to get it to format properly, probably not the "correct" way - I use a method from my bean that is being rendered in my table to format the value and return it as a String. The problem I have now is that when I sort, I'm sorting strings, when it really needs to be sorting number, dates, etc.

Here's what I have in my .page file:

<component id="membersTableView" type="contrib:TableView">
    <binding name="source" value="ognl:members" />
    <binding name="columns">
         Account Number:accountNumber, First Name:firstName, Last
Avg Purchase:"$" + formatCurrency(amount), Number Visits:formatNumber(visitCnt),
         Last Date:formatDate(lastDate)
    </binding>
</component>

<component id="membersTableColumns" type="contrib:TableColumns" /> <component id="membersTablePages" type="contrib:TablePages" /> <component id="membersTableFormRows" type="contrib:TableRows"></component>

<component id="membersTableValues" type="contrib:TableValues" />

The methods (formatCurrency, formatNumber, formatDate) are in my "Member"
bean that the table is rendering. So this works for the format, but when I sort by clicking on the column headers they are now strings, which doesn't work as needed.

Any advice is greatly appreciated.

Thanks,
Joe





---------------------------------------------------------------------
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]

Reply via email to