You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Titi Wangsa <bl...@gmail.com> on 2006/10/08 08:52:19 UTC

Remembering "first" attribute in t:dataTable

i have a session backed list
which gets displayed in a t:dataTable

which works great..

then i use the scroller to display a few items in each page

which works great

however each item in the table can be clicks to
display the details of the item.

on these details page, there is link which points back to the listing page

but once i get back to the listing page, the first page is displayed.
which is not so great.

I've located the problem in the t:dataTable's "first" attribute,
but setting that value to first="#{listStudentst.first}", where
listStudent is a session backed bean, and first is an Integer, results
in the value gets read with the table is rendered.
Which is half of what i need.

The other half is for the table's first attribute to be saved in the
session backed bean.
Which is what is troubling me..
any help?

Re: Remembering "first" attribute in t:dataTable

Posted by Jeff Bischoff <jb...@klkurz.com>.
Here is the wiki page [1].

Feel free to let me know what you think, and of course further 
contributions to the wiki are appreciated.

[1] http://wiki.apache.org/myfaces/ManagingDataScrollerPage

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates

Jeff Bischoff wrote:
> Titi,
> 
> This question is asked a lot, so I've decided to make a wiki page on it. 
> You can expect that page up by the end of today, unless some disaster 
> happens at work. Rather than make you wait, I'll give a quick version of 
> my answer here.
> 
> I gave you a tip on this in another thread [1]. But what I left out is 
> this last part: how to get the first attribute set.
> 
> There are two approaches, depending on your situation. If the data is 
> being reloaded between requests, and the indexes thus may change, you 
> will need to rely on some unique key in your data. Remembering the key 
> of the selected item from the last request, you iterate through the new 
> list until you find it, and then manually set the selectedIndex on the 
> dataTable backing bean. This is why I do generally, in my application.
> 
> If you're not reloading your list, or if the ordering is such that the 
> indexes won't change, you can cut through all this and use a neat little 
> trick in your dataTable columns. Whichever column(s) have a commandLink 
> to drill down to the detail page, add an extra t:updateActionListener:
> 
> <t:updateActionListener property="#{dataTableBacking.selectedRowIndex}" 
> value="#{rowIndex}"/>
> 
> Where #{rowIndex} references the "rowIndexVar" we defined in our dataTable.
> 
> So
> 
> -----
> <h:column>
>   <f:facet name="header"><h:outputText value="ID:"/></f:facet>
>   <h:commandLink action="#{navigation.drillDown}" immediate="true">
>     <h:outputText value="#{data.id}"/>
>     <t:updateActionListener property="#{detailsBean.id}" 
> value="#{data.id}"/>
>   </h:commandLink>
> </h:column>
> ------
> 
> Becomes
> 
> ------
> <h:column>
>   <f:facet name="header"><h:outputText value="ID:"/></f:facet>
>   <h:commandLink action="#{navigation.drillDown}" immediate="true">
>     <h:outputText value="#{data.id}"/>
>     <t:updateActionListener property="#{detailsBean.id}" 
> value="#{data.id}"/>
>     <t:updateActionListener 
> property="#{dataTableBacking.selectedRowIndex}" value="#{rowIndex}"/>
>   </h:commandLink>
> </h:column>
> ------
> 
> 
> 
> [1] http://www.nabble.com/Drill-Down-help-tf2275433.html#a6321951
> 
> Regards,
> 
> Jeff Bischoff
> Kenneth L Kurz & Associates, Inc.
> 
> Titi Wangsa wrote:
>> i have a session backed list
>> which gets displayed in a t:dataTable
>>
>> which works great..
>>
>> then i use the scroller to display a few items in each page
>>
>> which works great
>>
>> however each item in the table can be clicks to
>> display the details of the item.
>>
>> on these details page, there is link which points back to the listing 
>> page
>>
>> but once i get back to the listing page, the first page is displayed.
>> which is not so great.
>>
>> I've located the problem in the t:dataTable's "first" attribute,
>> but setting that value to first="#{listStudentst.first}", where
>> listStudent is a session backed bean, and first is an Integer, results
>> in the value gets read with the table is rendered.
>> Which is half of what i need.
>>
>> The other half is for the table's first attribute to be saved in the
>> session backed bean.
>> Which is what is troubling me..
>> any help?
>>
>>
>>
> 
> 
> 
> 
> 



Re: Remembering "first" attribute in t:dataTable

Posted by Jeff Bischoff <jb...@klkurz.com>.
Titi,

This question is asked a lot, so I've decided to make a wiki page on it. 
You can expect that page up by the end of today, unless some disaster 
happens at work. Rather than make you wait, I'll give a quick version of 
my answer here.

I gave you a tip on this in another thread [1]. But what I left out is 
this last part: how to get the first attribute set.

There are two approaches, depending on your situation. If the data is 
being reloaded between requests, and the indexes thus may change, you 
will need to rely on some unique key in your data. Remembering the key 
of the selected item from the last request, you iterate through the new 
list until you find it, and then manually set the selectedIndex on the 
dataTable backing bean. This is why I do generally, in my application.

If you're not reloading your list, or if the ordering is such that the 
indexes won't change, you can cut through all this and use a neat little 
trick in your dataTable columns. Whichever column(s) have a commandLink 
to drill down to the detail page, add an extra t:updateActionListener:

<t:updateActionListener property="#{dataTableBacking.selectedRowIndex}" 
value="#{rowIndex}"/>

Where #{rowIndex} references the "rowIndexVar" we defined in our dataTable.

So

-----
<h:column>
   <f:facet name="header"><h:outputText value="ID:"/></f:facet>
   <h:commandLink action="#{navigation.drillDown}" immediate="true">
     <h:outputText value="#{data.id}"/>
     <t:updateActionListener property="#{detailsBean.id}" 
value="#{data.id}"/>
   </h:commandLink>
</h:column>
------

Becomes

------
<h:column>
   <f:facet name="header"><h:outputText value="ID:"/></f:facet>
   <h:commandLink action="#{navigation.drillDown}" immediate="true">
     <h:outputText value="#{data.id}"/>
     <t:updateActionListener property="#{detailsBean.id}" 
value="#{data.id}"/>
     <t:updateActionListener 
property="#{dataTableBacking.selectedRowIndex}" value="#{rowIndex}"/>
   </h:commandLink>
</h:column>
------



[1] http://www.nabble.com/Drill-Down-help-tf2275433.html#a6321951

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

Titi Wangsa wrote:
> i have a session backed list
> which gets displayed in a t:dataTable
> 
> which works great..
> 
> then i use the scroller to display a few items in each page
> 
> which works great
> 
> however each item in the table can be clicks to
> display the details of the item.
> 
> on these details page, there is link which points back to the listing page
> 
> but once i get back to the listing page, the first page is displayed.
> which is not so great.
> 
> I've located the problem in the t:dataTable's "first" attribute,
> but setting that value to first="#{listStudentst.first}", where
> listStudent is a session backed bean, and first is an Integer, results
> in the value gets read with the table is rendered.
> Which is half of what i need.
> 
> The other half is for the table's first attribute to be saved in the
> session backed bean.
> Which is what is troubling me..
> any help?
> 
> 
> 



Re: Remembering "first" attribute in t:dataTable

Posted by Aneesha Govil <po...@gmail.com>.
Well I have the same usecase. I am using the approach on the below-mentioned
link. Try it..

http://marc2.theaimsgroup.com/?l=myfaces-user&m=113874875226923&w=2

I am not using the datatable's first attribute. I don't know how to make
this work with that.

Hope that helps!

Aneesha

On 10/8/06, Titi Wangsa <bl...@gmail.com> wrote:
>
> i have a session backed list
> which gets displayed in a t:dataTable
>
> which works great..
>
> then i use the scroller to display a few items in each page
>
> which works great
>
> however each item in the table can be clicks to
> display the details of the item.
>
> on these details page, there is link which points back to the listing page
>
> but once i get back to the listing page, the first page is displayed.
> which is not so great.
>
> I've located the problem in the t:dataTable's "first" attribute,
> but setting that value to first="#{listStudentst.first}", where
> listStudent is a session backed bean, and first is an Integer, results
> in the value gets read with the table is rendered.
> Which is half of what i need.
>
> The other half is for the table's first attribute to be saved in the
> session backed bean.
> Which is what is troubling me..
> any help?
>