You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ephraim Rosenfeld <er...@knoa.com> on 2014/09/09 18:01:00 UTC

Referencing DataTable rows within the table column header

Hello All,

I am creating a table with a DropDownChoice component in the header of one of the columns. When a selection is made in the drop down in the column header, I want to update all of the rows in the table.

Would the following snippet be the best approach to reference each row Item component from the column header, or is there an alternative to using the get() method?

Thank you in advance,

- Ephraim

WebMarkupContainer container = ((WebMarkupContainer)dropDownChoice.findParent(DataTable.class).get(1));
               DataGridView                 gridView  = (DataGridView)container.get(0);
               for(int i = 0; i < NUM_OF_ROWS; i++) {
                   Item item = (Item)gridView.get(i);
                // do row updates
                }

Re: Referencing DataTable rows within the table column header

Posted by Paul Bors <pa...@bors.ws>.
Another piece of advice,

Avoid unnecessary casts (Wicket 6 supports generics) and try not to use
code to navigate the wicket component tree unnecessary like this line of
code:

WebMarkupContainer container = ((WebMarkupContainer)
dropDownChoice.findParent(DataTable.class).get(1));

Get familiar with the best practices documented at:
http://wicket.apache.org/guide/guide/single.html#bestpractices

You should give the free guide a read back to back and treat it as your
bible until you get a bit more intimate with Wicket :)

Other resources available for you to learn and master Wicket are the Wicket
Stuff (http://wicketstuff.org/) and the examples at:
http://www.wicket-library.com/wicket-examples-6.0.x/index.html

Get familiar to those as well.

For a filter toolbar see:
http://www.wicket-library.com/wicket-examples-6.0.x/repeater/wicket/bookmarkable/org.apache.wicket.examples.repeater.DataTableFilterToolbarPage;jsessionid=03E1374082C8198F0F052CED6E54F7A1?0

Although is not using a drop-down but you'll get the idea :)

~ Thank you,
   Paul Bors


On Tue, Sep 9, 2014 at 2:57 PM, Paul Bors <pa...@bors.ws> wrote:

> Hey Ephraim,
>
> At Knoa for the console code I created an API around those components.
> You don't have to re-invent the wheel, all you have to do is get familiar
> with the console commons and which DropDown component to use.
>
> Remember wicket is a component driven framework similar to Swing.
>
> I would recommend using one of the Ajax enabled drop downs and override
> the method to refresh the data table rows of interest. There are plenty of
> examples in the console's code base... look at how other table such as the
> ones for the End User attributes are refreshed or how the edit button in a
> table cell will turn the table row into form components. Use the same
> principle.
>
> Also, if this is just a filter toolbar, then look at how other Ajax filter
> toolbars work and you won't loos focus of the drop down since it's Ajax
> that does the refresh.
>
> If you are to re-implement this from scratch and re-invent the wheel you
> can also but I won't recommend it.
> Just look over the current available components in your commons API and
> use the appropriate one, or extend it and make it do what you need.
>
> Martin was referring to the event mechanism build in Wicket documented in
> the Wicket Guide at:
> http://wicket.apache.org/guide/guide/single.html#advanced_1
>
> But for a simple filter toolbar you don't need to get that complicated.
>
> ~ Have fun,
>    Paul Bors
>
> On Tue, Sep 9, 2014 at 12:29 PM, Ephraim Rosenfeld <er...@knoa.com>
> wrote:
>
>> Hi Martin:
>>
>>
>>
>> Thank you for your quick response.
>>
>>
>>
>> I was initially updating the entire table, but that was causing me to
>> lose focus from the drop-down menu in which I made the selection. Also, my
>> hope was that I could update as few row items/components as possible,
>> thereby expediting the table-refresh process.
>>
>>
>>
>> When you mention 'Wicket's Event System', are you referring to
>> inter-component events, like the example portrayed here:
>> http://savicprvoslav.blogspot.com/2012/06/wicket-15-inter-component-events.html
>>
>>
>>
>> Regards,
>>
>>
>>
>> - Ephraim
>>
>>
>>
>> -----Original Message-----
>> From: Martin Grigorov [mailto:mgrigorov@apache.org]
>> Sent: Tuesday, September 09, 2014 12:10 PM
>> To: users@wicket.apache.org
>> Subject: Re: Referencing DataTable rows within the table column header
>>
>>
>>
>> Hi,
>>
>>
>>
>> Why don't you update the table itself ? This will update all its children
>> components too.
>>
>>
>>
>> Otherwise I'd use Wicket's Event system to send a notification to all
>> interested parties.
>>
>>
>>
>> Martin Grigorov
>>
>> Wicket Training and Consulting
>>
>> https://twitter.com/mtgrigorov
>>
>>
>>
>>
>>
>> On Tue, Sep 9, 2014 at 7:01 PM, Ephraim Rosenfeld <erosenfeld@knoa.com
>> <ma...@knoa.com>>
>>
>> wrote:
>>
>>
>>
>> > Hello All,
>>
>> >
>>
>> > I am creating a table with a DropDownChoice component in the header of
>>
>> > one of the columns. When a selection is made in the drop down in the
>>
>> > column header, I want to update all of the rows in the table.
>>
>> >
>>
>> > Would the following snippet be the best approach to reference each row
>>
>> > Item component from the column header, or is there an alternative to
>>
>> > using the get() method?
>>
>> >
>>
>> > Thank you in advance,
>>
>> >
>>
>> > - Ephraim
>>
>> >
>>
>> > WebMarkupContainer container =
>>
>> > ((WebMarkupContainer)dropDownChoice.findParent(DataTable.class).get(1));
>>
>> >                DataGridView                 gridView  =
>>
>> > (DataGridView)container.get(0);
>>
>> >                for(int i = 0; i < NUM_OF_ROWS; i++) {
>>
>> >                    Item item = (Item)gridView.get(i);
>>
>> >                 // do row updates
>>
>> >                 }
>>
>> >
>>
>
>

Re: Referencing DataTable rows within the table column header

Posted by Paul Bors <pa...@bors.ws>.
Hey Ephraim,

At Knoa for the console code I created an API around those components.
You don't have to re-invent the wheel, all you have to do is get familiar
with the console commons and which DropDown component to use.

Remember wicket is a component driven framework similar to Swing.

I would recommend using one of the Ajax enabled drop downs and override the
method to refresh the data table rows of interest. There are plenty of
examples in the console's code base... look at how other table such as the
ones for the End User attributes are refreshed or how the edit button in a
table cell will turn the table row into form components. Use the same
principle.

Also, if this is just a filter toolbar, then look at how other Ajax filter
toolbars work and you won't loos focus of the drop down since it's Ajax
that does the refresh.

If you are to re-implement this from scratch and re-invent the wheel you
can also but I won't recommend it.
Just look over the current available components in your commons API and use
the appropriate one, or extend it and make it do what you need.

Martin was referring to the event mechanism build in Wicket documented in
the Wicket Guide at:
http://wicket.apache.org/guide/guide/single.html#advanced_1

But for a simple filter toolbar you don't need to get that complicated.

~ Have fun,
   Paul Bors

On Tue, Sep 9, 2014 at 12:29 PM, Ephraim Rosenfeld <er...@knoa.com>
wrote:

> Hi Martin:
>
>
>
> Thank you for your quick response.
>
>
>
> I was initially updating the entire table, but that was causing me to lose
> focus from the drop-down menu in which I made the selection. Also, my hope
> was that I could update as few row items/components as possible, thereby
> expediting the table-refresh process.
>
>
>
> When you mention 'Wicket's Event System', are you referring to
> inter-component events, like the example portrayed here:
> http://savicprvoslav.blogspot.com/2012/06/wicket-15-inter-component-events.html
>
>
>
> Regards,
>
>
>
> - Ephraim
>
>
>
> -----Original Message-----
> From: Martin Grigorov [mailto:mgrigorov@apache.org]
> Sent: Tuesday, September 09, 2014 12:10 PM
> To: users@wicket.apache.org
> Subject: Re: Referencing DataTable rows within the table column header
>
>
>
> Hi,
>
>
>
> Why don't you update the table itself ? This will update all its children
> components too.
>
>
>
> Otherwise I'd use Wicket's Event system to send a notification to all
> interested parties.
>
>
>
> Martin Grigorov
>
> Wicket Training and Consulting
>
> https://twitter.com/mtgrigorov
>
>
>
>
>
> On Tue, Sep 9, 2014 at 7:01 PM, Ephraim Rosenfeld <erosenfeld@knoa.com
> <ma...@knoa.com>>
>
> wrote:
>
>
>
> > Hello All,
>
> >
>
> > I am creating a table with a DropDownChoice component in the header of
>
> > one of the columns. When a selection is made in the drop down in the
>
> > column header, I want to update all of the rows in the table.
>
> >
>
> > Would the following snippet be the best approach to reference each row
>
> > Item component from the column header, or is there an alternative to
>
> > using the get() method?
>
> >
>
> > Thank you in advance,
>
> >
>
> > - Ephraim
>
> >
>
> > WebMarkupContainer container =
>
> > ((WebMarkupContainer)dropDownChoice.findParent(DataTable.class).get(1));
>
> >                DataGridView                 gridView  =
>
> > (DataGridView)container.get(0);
>
> >                for(int i = 0; i < NUM_OF_ROWS; i++) {
>
> >                    Item item = (Item)gridView.get(i);
>
> >                 // do row updates
>
> >                 }
>
> >
>

RE: Referencing DataTable rows within the table column header

Posted by Ephraim Rosenfeld <er...@knoa.com>.
Hi Martin:



Thank you for your quick response.



I was initially updating the entire table, but that was causing me to lose focus from the drop-down menu in which I made the selection. Also, my hope was that I could update as few row items/components as possible, thereby expediting the table-refresh process.



When you mention 'Wicket's Event System', are you referring to inter-component events, like the example portrayed here: http://savicprvoslav.blogspot.com/2012/06/wicket-15-inter-component-events.html



Regards,



- Ephraim



-----Original Message-----
From: Martin Grigorov [mailto:mgrigorov@apache.org]
Sent: Tuesday, September 09, 2014 12:10 PM
To: users@wicket.apache.org
Subject: Re: Referencing DataTable rows within the table column header



Hi,



Why don't you update the table itself ? This will update all its children components too.



Otherwise I'd use Wicket's Event system to send a notification to all interested parties.



Martin Grigorov

Wicket Training and Consulting

https://twitter.com/mtgrigorov





On Tue, Sep 9, 2014 at 7:01 PM, Ephraim Rosenfeld <er...@knoa.com>>

wrote:



> Hello All,

>

> I am creating a table with a DropDownChoice component in the header of

> one of the columns. When a selection is made in the drop down in the

> column header, I want to update all of the rows in the table.

>

> Would the following snippet be the best approach to reference each row

> Item component from the column header, or is there an alternative to

> using the get() method?

>

> Thank you in advance,

>

> - Ephraim

>

> WebMarkupContainer container =

> ((WebMarkupContainer)dropDownChoice.findParent(DataTable.class).get(1));

>                DataGridView                 gridView  =

> (DataGridView)container.get(0);

>                for(int i = 0; i < NUM_OF_ROWS; i++) {

>                    Item item = (Item)gridView.get(i);

>                 // do row updates

>                 }

>

Re: Referencing DataTable rows within the table column header

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Why don't you update the table itself ? This will update all its children
components too.

Otherwise I'd use Wicket's Event system to send a notification to all
interested parties.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov


On Tue, Sep 9, 2014 at 7:01 PM, Ephraim Rosenfeld <er...@knoa.com>
wrote:

> Hello All,
>
> I am creating a table with a DropDownChoice component in the header of one
> of the columns. When a selection is made in the drop down in the column
> header, I want to update all of the rows in the table.
>
> Would the following snippet be the best approach to reference each row
> Item component from the column header, or is there an alternative to using
> the get() method?
>
> Thank you in advance,
>
> - Ephraim
>
> WebMarkupContainer container =
> ((WebMarkupContainer)dropDownChoice.findParent(DataTable.class).get(1));
>                DataGridView                 gridView  =
> (DataGridView)container.get(0);
>                for(int i = 0; i < NUM_OF_ROWS; i++) {
>                    Item item = (Item)gridView.get(i);
>                 // do row updates
>                 }
>