You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Zeldor <pg...@gmail.com> on 2011/06/07 08:53:04 UTC

DataView the easy way?

Hi,

I am trying to make my first DataView and I found an example that does what
I want. It's quite confusing though - it takes like 15 pages and classes to
do it and I cannot decipher it. 
http://wicketstuff.org/wicket14/repeater/?wicket:bookmarkablePage=:org.apache.wicket.examples.repeater.SimplePage
http://wicketstuff.org/wicket14/repeater/?wicket:bookmarkablePage=:org.apache.wicket.examples.repeater.SimplePage 

So, any ideas how to do it fast, just on one page? I have a HashTable with
ArrayLists [HashTable&lt;Integer, ArrayList&lt;Long&gt;>] that I want to
display. Of course I don't know how many rows I will have, that's why I want
DataView. I want to display 3 first data from the ArrayList in the map and I
want to be able to select rows [so I can delete them by int id].

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/DataView-the-easy-way-tp3578760p3578760.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DataView the easy way?

Posted by Martin Grigorov <mg...@apache.org>.
try with  item.add(new Label("title", expedition.get(0).toString()));

On Tue, Jun 7, 2011 at 1:07 PM, Zeldor <pg...@gmail.com> wrote:
> I almost have it... I have my ArrayList of lists, so I guess my code should
> look smth like that:
>
>
> ArrayList&lt;ArrayList&lt;Long&gt;> colonisations =
> MySession.loggedInUser.colonisations;
>                add(new DataView("expeditionsView", new ListDataProvider(colonisations))
>         {
>             @Override
>             protected void populateItem(final Item item)
>             {
>                 ArrayList expedition = (ArrayList)item.getModelObject();
>                // "item" represents the current "row-component"
>                 item.add(new Label("title", expedition.get(0)));
>                 item.add(new Label("price", expedition.get(1)));
>             }
>         });
>
> I must be doing some fundamental mistake here, as it can't work. It throws
> "cannot find symbol: symbol constructor Label" at both item.add lines
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/DataView-the-easy-way-tp3578760p3579270.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DataView the easy way?

Posted by Zeldor <pg...@gmail.com>.
I almost have it... I have my ArrayList of lists, so I guess my code should
look smth like that:


ArrayList&lt;ArrayList&lt;Long&gt;> colonisations =
MySession.loggedInUser.colonisations;
		add(new DataView("expeditionsView", new ListDataProvider(colonisations))
         {
             @Override
             protected void populateItem(final Item item)
             {
                 ArrayList expedition = (ArrayList)item.getModelObject();               
                // "item" represents the current "row-component"
                 item.add(new Label("title", expedition.get(0)));
                 item.add(new Label("price", expedition.get(1)));
             }
         }); 

I must be doing some fundamental mistake here, as it can't work. It throws
"cannot find symbol: symbol constructor Label" at both item.add lines

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/DataView-the-easy-way-tp3578760p3579270.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DataView the easy way?

Posted by Achim Wiedemann <we...@googlemail.com>.
Hi Zeldor,

the populateItem-method is used to populate the rows of your table. 
Basically, you can add the "cells" of your rows there. DataView will 
loop through the elements of your collection automatically, and for 
every element in the collection call the populateItem-method with the 
current element passed as a parameter.

So by slightly modifying the SimplePage that Martin suggested to match 
your case you should get something like this:


List<Expedition> colonisations = ...; // initialized somewhere else
add(
   new DataView<Expedition>(
     "expeditionsView",
     new ListDataProvider<Expedition>(colonisations)
   )
         {
             @Override
             protected void populateItem(final Item<Expedition> item)
             {
                 Expedition expedition = item.getModelObject();
		
		// "item" represents the current "row-component"
                 item.add(new Label("title", expedition.getTitle());
                 item.add(new Label("price", expedition.getPrice())
             }
         }
);


As you can see, you're just populating your table-rows' cells with the 
components you need. Instead of Labels you could also add Buttons or 
whatever you like.


greetz,
achim



Am 07.06.2011 12:10, schrieb Zeldor:
> Ok, I changed it to ArrayList&lt;ArrayList&lt;Long&gt;>, but I still don't
> get how to use populateItem...
>
>
> Even testing just that
> add(new DataView<Expedition>("expedition",
> MySession.loggedInUser.colonisations)
>          {
>
>          });
>
> Results in:
> internal error; cannot instantiate org.
> apache.wicket.markup.repeater.data.DateView.<init>  at
> org.apache.wicket.markup.repeater.data.DAtaView<Expedition>  to ()
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/DataView-the-easy-way-tp3578760p3579173.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DataView the easy way?

Posted by Zeldor <pg...@gmail.com>.
Ok, I changed it to ArrayList&lt;ArrayList&lt;Long&gt;>, but I still don't
get how to use populateItem...


Even testing just that
add(new DataView<Expedition>("expedition",
MySession.loggedInUser.colonisations)
        {
            
        });

Results in:
internal error; cannot instantiate org.
apache.wicket.markup.repeater.data.DateView.<init> at
org.apache.wicket.markup.repeater.data.DAtaView<Expedition> to ()

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/DataView-the-easy-way-tp3578760p3579173.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DataView the easy way?

Posted by Zeldor <pg...@gmail.com>.
Thanks a lot, it works :)

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/DataView-the-easy-way-tp3578760p3579384.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DataView the easy way?

Posted by Zeldor <pg...@gmail.com>.
Do I need to do anything special? Will it automatically go through all rows
of my Map? When my map is HashMap&lt;Integer,ArrayList&gt; then Expedition
will be my ArrayList or whole row, together with int id? I could probably
use just a list of ArrayLists if it'd be easier...

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/DataView-the-easy-way-tp3578760p3579147.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DataView the easy way?

Posted by Martin Grigorov <mg...@apache.org>.
populateItem() gives you one Expedition at a time. You decide how to render it.

On Tue, Jun 7, 2011 at 11:42 AM, Zeldor <pg...@gmail.com> wrote:
> Right :)
>
>
> So I want to start with something like:
>
> add(new DataView<Expedition>("expedition",
> MySession.loggedInUser.colonisations) {
> });
>
> I am confused how to implement populateItem though...
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/DataView-the-easy-way-tp3578760p3579124.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DataView the easy way?

Posted by Zeldor <pg...@gmail.com>.
Right :)


So I want to start with something like:

add(new DataView<Expedition>("expedition",
MySession.loggedInUser.colonisations) {
});

I am confused how to implement populateItem though...


     

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/DataView-the-easy-way-tp3578760p3579124.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DataView the easy way?

Posted by Martin Grigorov <mg...@apache.org>.
There are 15+ pages because there are examples for several components
in this folder.
Just take a look at SimplePage.java and it should become clear how to do it.

On Tue, Jun 7, 2011 at 8:53 AM, Zeldor <pg...@gmail.com> wrote:
> Hi,
>
> I am trying to make my first DataView and I found an example that does what
> I want. It's quite confusing though - it takes like 15 pages and classes to
> do it and I cannot decipher it.
> http://wicketstuff.org/wicket14/repeater/?wicket:bookmarkablePage=:org.apache.wicket.examples.repeater.SimplePage
> http://wicketstuff.org/wicket14/repeater/?wicket:bookmarkablePage=:org.apache.wicket.examples.repeater.SimplePage
>
> So, any ideas how to do it fast, just on one page? I have a HashTable with
> ArrayLists [HashTable&lt;Integer, ArrayList&lt;Long&gt;>] that I want to
> display. Of course I don't know how many rows I will have, that's why I want
> DataView. I want to display 3 first data from the ArrayList in the map and I
> want to be able to select rows [so I can delete them by int id].
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/DataView-the-easy-way-tp3578760p3578760.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org