You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Thai Tran <bu...@gmail.com> on 2013/12/13 11:22:23 UTC
Excluding the last element in List during sorting
Hi all,
On my grid, each cell contains a textbox in order to let user edit the
data. The last row of the grid is cells which contains empty textbox in
order to let user insert the new data. In order to create the last row,
I manually add a new element during retrieving data from database
/
//public void setupRender() {//
// List<Document> docs = documentDAO.getAll();//
// docs.add(new Document());//
.....
//}/
/public BeanModel<Document> getDocumentModel(){//
// BeanModel<Document> model =
getBeanModelSource().createDisplayModel(Document.class, getMessages());//
// model.include("name", "shortDescription");//
// model.add("delete", null);//
//
// return model;//
//}/
and the tml file:
/<t:parameter name="nameCell">//
// <input t:type="TextField" t:value="document.name" t:id="nameField"
/>//
//</t:parameter>//
////
//<t:parameter name="shortDescriptionCell">//
// <input t:type="TextField" t:value="document.shortDescription" />//
//</t:parameter>/
.....
Everything work great; however, when I sort a column of the grid, the
last row will jump into the first position, since the empty document
(row /element) is included during sorting. How can I override the
sorting function to exclude the last element in the list ?
Regards
Re: Excluding the last element in List during sorting
Posted by Lance Java <la...@googlemail.com>.
You'll need your own GridDataSource implementation and a custom
implementation for
void prepare(int startIndex, int endIndex,
List<SortConstraint> sortConstraints)
Since you're using a list, it'll be easy to extend CollectionGridDataSource.
Re: Excluding the last element in List during sorting
Posted by Lance Java <la...@googlemail.com>.
I'm assuming it's obvious that the source of the list is irrelevant and
that my solution will work regardless.
Re: Excluding the last element in List during sorting
Posted by Thai Tran <bu...@gmail.com>.
<t:fcomponents.stupidfilter t:id="filter" dataSource="thisMustBeAList"
.... />
<t:grid source="filter.listOfTheFilter" ... />
But thank for your explain. I think I will change the source to the
griddatasource like your suggestion and then trying to merge the filter
with my custom griddatasource
On 12/17/2013 6:45 PM, Lance Java wrote:
> Eg: https://gist.github.com/uklance/8003728
>
> NB not tested and needs to be tweaked to support paging.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Excluding the last element in List during sorting
Posted by Lance Java <la...@googlemail.com>.
> Awesome, it is working now
Great!
> THANK A LOT, LANCE
You're welcome :)
Re: Excluding the last element in List during sorting
Posted by Thai Tran <bu...@gmail.com>.
Awesome, it is working now
THANK A LOT, LANCE
On 12/17/2013 6:45 PM, Lance Java wrote:
> Eg: https://gist.github.com/uklance/8003728
>
> NB not tested and needs to be tweaked to support paging.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Excluding the last element in List during sorting
Posted by Lance Java <la...@googlemail.com>.
Eg: https://gist.github.com/uklance/8003728
NB not tested and needs to be tweaked to support paging.
Re: Excluding the last element in List during sorting
Posted by Lance Java <la...@googlemail.com>.
Yes, and as I said the grid component ALWAYS acts upon a GridDataSource
even if you provide a List.
So, instead of passing a List to the grid (and having Tapestry create a
CollectionGridDataSource under the hood) you should pass your own custom
GridDataSource.
This custom GridDataSource will delegate through to your list. It will
probably do this by extending CollectionGridDataSource. It will exclude the
last dummy row from sorting.
Re: Excluding the last element in List during sorting
Posted by Thai Tran <bu...@gmail.com>.
Hi Lance,
Like I said in the previous email, grid can only take a list from a
Filter component in my current system (since the filter only return a
list to the outside, nothing else). Modified a component will require a
lot of crazy talking (which I wanna take away of) to other developers
and PM.
On 12/17/2013 4:29 PM, Lance Java wrote:
> Tapestry's grid expects a GridDataSource as the "source" parameter.
>
> What you may not know is that tapestry has a TypeCoercer to make things
> easy for us. If you provide a list as the source of a grid, tapestry will
> happily TypeCoerce the list to a GridDataSource (which is what is happening
> in your case).
>
> So, instead of passing a list as the "source" you should pass a custom
> GridDataSource implementation. You might find it easy to extend (or
> delegate to) CollectionGridDataSource.
>
> You'll need to take care with paging.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Excluding the last element in List during sorting
Posted by Lance Java <la...@googlemail.com>.
Tapestry's grid expects a GridDataSource as the "source" parameter.
What you may not know is that tapestry has a TypeCoercer to make things
easy for us. If you provide a list as the source of a grid, tapestry will
happily TypeCoerce the list to a GridDataSource (which is what is happening
in your case).
So, instead of passing a list as the "source" you should pass a custom
GridDataSource implementation. You might find it easy to extend (or
delegate to) CollectionGridDataSource.
You'll need to take care with paging.
Re: Excluding the last element in List during sorting
Posted by Thai Tran <bu...@gmail.com>.
I looked at the tapestry grid and also the GridDataSource. I think it is
possible to do that. However, things are quite complicated because at
this moment, our system are set the source of the grid from a list
retrieved from a custom filter component.
Grid -- look up list of --> Filter Component -- look up only list type
of --> List retrieved from database
So, is there any way to modified the list during page submitted and the
hook the modified up before processing sorting ?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Excluding the last element in List during sorting
Posted by Eugen <eu...@gmail.com>.
Oh sorry, it was a wrong tip,...
You can provide an own GridDataSource, in getAvailableRows() return
your list size+1 (the empty row) and in getRowValue(index) return an
emty object for the index out of the list size.
The empty row will not be included in sort.
Regards
2013/12/13 Eugen <eu...@gmail.com>:
> Hi,
> have You tried to provide an own sortModel?
>
> 2013/12/13 Thai Tran <bu...@gmail.com>:
>> Hi all,
>>
>> On my grid, each cell contains a textbox in order to let user edit the data.
>> The last row of the grid is cells which contains empty textbox in order to
>> let user insert the new data. In order to create the last row, I manually
>> add a new element during retrieving data from database
>> /
>> //public void setupRender() {//
>> // List<Document> docs = documentDAO.getAll();//
>> // docs.add(new Document());//
>> .....
>> //}/
>>
>> /public BeanModel<Document> getDocumentModel(){//
>> // BeanModel<Document> model =
>> getBeanModelSource().createDisplayModel(Document.class, getMessages());//
>> // model.include("name", "shortDescription");//
>> // model.add("delete", null);//
>> //
>> // return model;//
>> //}/
>>
>> and the tml file:
>>
>> /<t:parameter name="nameCell">//
>> // <input t:type="TextField" t:value="document.name" t:id="nameField"
>> />//
>> //</t:parameter>//
>> ////
>> //<t:parameter name="shortDescriptionCell">//
>> // <input t:type="TextField" t:value="document.shortDescription" />//
>> //</t:parameter>/
>> .....
>>
>> Everything work great; however, when I sort a column of the grid, the last
>> row will jump into the first position, since the empty document (row
>> /element) is included during sorting. How can I override the sorting
>> function to exclude the last element in the list ?
>>
>> Regards
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Excluding the last element in List during sorting
Posted by Eugen <eu...@gmail.com>.
Hi,
have You tried to provide an own sortModel?
2013/12/13 Thai Tran <bu...@gmail.com>:
> Hi all,
>
> On my grid, each cell contains a textbox in order to let user edit the data.
> The last row of the grid is cells which contains empty textbox in order to
> let user insert the new data. In order to create the last row, I manually
> add a new element during retrieving data from database
> /
> //public void setupRender() {//
> // List<Document> docs = documentDAO.getAll();//
> // docs.add(new Document());//
> .....
> //}/
>
> /public BeanModel<Document> getDocumentModel(){//
> // BeanModel<Document> model =
> getBeanModelSource().createDisplayModel(Document.class, getMessages());//
> // model.include("name", "shortDescription");//
> // model.add("delete", null);//
> //
> // return model;//
> //}/
>
> and the tml file:
>
> /<t:parameter name="nameCell">//
> // <input t:type="TextField" t:value="document.name" t:id="nameField"
> />//
> //</t:parameter>//
> ////
> //<t:parameter name="shortDescriptionCell">//
> // <input t:type="TextField" t:value="document.shortDescription" />//
> //</t:parameter>/
> .....
>
> Everything work great; however, when I sort a column of the grid, the last
> row will jump into the first position, since the empty document (row
> /element) is included during sorting. How can I override the sorting
> function to exclude the last element in the list ?
>
> Regards
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org