Thanks, Shing.

I was hoping there'd be something a little more direct (like, a
meta/injected property on the getTable().getTableRow(), but oh well.)

So, to close the loop, this is the "most performant" means I can think
of to get the ordinal numbers displayed in a Contrib:Table *without*
actually saving the ordinal numbers in the source List...

I'm pretty sure this is "pool safe" in that 2 different users won't end
up getting mixed up ordinal displays.

HTML
---------
        <table jwcid="table" cellpadding="0" cellspacing="0">
        <tr class="headerRow">
           ...snip...     
        </tr>
        <tr>
            <td jwcid="ordinalColumnValue">
                <span jwcid="ordinalNumber">1</span>
            </td>


.page File
----------
        <component id="table" type="contrib:Table">
             <binding name="source" value="documents"/>
             <binding name="columns" 
                   value="literal:ordinal:#:!ordinal, 
                          docId:Doc ID:docId, 
                          ....snip...."/>
        </component>

        <component id="ordinalColumnValue" type="Block"/>
        <component id="ordinalNumber" type="Insert">
                <binding name="value" value="ognl:ordinal"/>
        </component>


Java Code
---------
@InjectComponent("table")
public abstract Table getTable();
    
int ordinal;
int currentPage;
int currentPageSize;

// Can't use initialize() because getTable() is null at that point    
public void pageBeginRender(PageEvent event) {
 ordinal = 0;
 currentPage =
getTable().getTableModel().getPagingState().getCurrentPage();
 currentPageSize =
getTable().getTableModel().getPagingState().getPageSize();
}
    
    
public int getOrdinal() {
  ordinal++;
  return (currentPage * currentPageSize) + ordinal;
}


-----Original Message-----
From: Shing Hing Man [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 01, 2006 3:44 PM
To: Tapestry users
Subject: Re: Getting the ordinal # in the Contrib:Table

The method 
getCurrentPages in
org.apache.tapestry.contrib.table.components.TablesPages

returns the current page of  your table.

The ordinal number of  the first row of the current
page should be something like 

(tablesPages.getCurrentPage() - 1) * PAGE_SIZE) + 1


Shing


--- [EMAIL PROTECTED] wrote:

> I *hope* there's a really straightforward answer to
> this and that I'm
> just a complete donkey for overlooking it, but. . . 
> 
> If you want to have a table that iterates over a
> List and (for example)
> spit out some properties of each element in the
> List, to wit:
> 
> ---------------------------
> |Aaron |      (202) 123-4567|
> ---------------------------
> |Bob   |      (202) 987-6543|
> ---------------------------
> etc.etc.
> 
> That's really easy.
> 
> But now say you want to just add an ordinal number
> as the first column
> of the table, like this:
> 
> ---------------------------------
> | 1 | Aaron | (202) 123-4567|
> ---------------------------------
> | 2 | Bob   | (202) 987-6543|
> ---------------------------------     
> | 3 | etc. etc.
> 
> That seems to be harder.  The only way I see how to
> do it is to:
> 
> A) Define a custom columnValue @Block
> 
> B) Map that columnValue to some MyTable.java
> getOrdinal() method
> 
> C) In my getOrdinal() method, get the Object
> associated with
> getTable().getTableRow();
> 
> D) Assume the "source" data for the Table is a
> java.util.List, use the
> List.indexOf() method on the Object from step (C) to
> figure out what
> element it is and return that int value as the
> ordinal 
> 
> Please tell me I'm a donkey...
> 
> Thanks,
> Tom
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
> 


Home page :
  http://uk.geocities.com/matmsh/index.html

Send instant messages to your online friends
http://uk.messenger.yahoo.com 

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