Quantcast

Table repeater: repeat across row AND column

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Table repeater: repeat across row AND column

akarypid
Hello,

I am trying to create a web page that lists contact addresses in a table.  
My repeater can easily lay out one address per row, but I need to be able  
to list 2 addresses per row (actually, ideally I'd like to list N  
addresses per row). The problem is that ListView's operation  
[populateItem()] only provides you with one item to work with. So with  
this markup:

<html xmlns:wicket>
        <body>
                <wicket:panel>
                        <table wicket:id="addressesTable" style="width: 100%;">
                                <tr wicket:id="addresses">
                                        <td wicket:id="address" style="width: 50%;"></td>
                                        <!--
                                                I NEED ANOTHER CELL LIKE THE ONE ABOVE HERE
                                        <td wicket:id="address2" style="width: 50%;"></td>
                                        -->
                                </tr>
                        </table>
                </wicket:panel>
        </body>
</html>

If I uncomment the second cell above, I need to be able to access the  
"next" item, something like:

final ListView<Address> rowContainer = new ListView<Address>(
                "addresses", model) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<Address> item) {
                Address a = item.getModelObject();
                AddressPanel ap = new AddressPanel("address",
                        new CompoundPropertyModel<Address>(
                                        new AddressLoadableDetachableModel(a.getId())));
                item.add(ap);
/*
// DOES SUCH AN API EXIST?
//
                if (item.hasNext()) {
                        item.next();
                        a = item.getModelObject();
                        AddressPanel ap2 = new AddressPanel("address2",
                                new CompoundPropertyModel<Address>(
                                                new AddressLoadableDetachableModel(a.getId())));
                        item.add(ap2);
                }
*/
        }
};

My only solution currently is that I convert the list of addresses to a  
list of address tuples (pairs), so that I am able to repeat over pairs of  
addresses. In short, I am just wondering if there is a better way to do  
this rather than (pseudocode):

List<Address> addresses = myRepository.loadAddressList();
List<Tuple<Address,Address>> addressPairs = convertToPairs(addresses);
// Make the above repeater iterate over "List<Tuple<Address,Address>>"  
having access
// to two addresses per repetition

Any pointers on this? Thank you in advance.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Table repeater: repeat across row AND column

Martin Grigorov-4
I like your current approach better than what you want to do.
Anyway here is how to do it:

int currIndex = item.getIndex();

ListItem nextItem = get(Integer.toString(currIndex + 1));
if (nextItem != null) {
    ...
}


On Sun, May 1, 2011 at 6:51 PM, Alexandros Karypidis <[hidden email]> wrote:

> Hello,
>
> I am trying to create a web page that lists contact addresses in a table. My
> repeater can easily lay out one address per row, but I need to be able to
> list 2 addresses per row (actually, ideally I'd like to list N addresses per
> row). The problem is that ListView's operation [populateItem()] only
> provides you with one item to work with. So with this markup:
>
> <html xmlns:wicket>
>        <body>
>                <wicket:panel>
>                        <table wicket:id="addressesTable" style="width:
> 100%;">
>                                <tr wicket:id="addresses">
>                                        <td wicket:id="address" style="width:
> 50%;"></td>
>                                        <!--
>                                                I NEED ANOTHER CELL LIKE THE
> ONE ABOVE HERE
>                                        <td wicket:id="address2"
> style="width: 50%;"></td>
>                                        -->
>                                </tr>
>                        </table>
>                </wicket:panel>
>        </body>
> </html>
>
> If I uncomment the second cell above, I need to be able to access the "next"
> item, something like:
>
> final ListView<Address> rowContainer = new ListView<Address>(
>                "addresses", model) {
>        private static final long serialVersionUID = 1L;
>
>        @Override
>        protected void populateItem(ListItem<Address> item) {
>                Address a = item.getModelObject();
>                AddressPanel ap = new AddressPanel("address",
>                        new CompoundPropertyModel<Address>(
>                                        new
> AddressLoadableDetachableModel(a.getId())));
>                item.add(ap);
> /*
> // DOES SUCH AN API EXIST?
> //
>                if (item.hasNext()) {
>                        item.next();
>                        a = item.getModelObject();
>                        AddressPanel ap2 = new AddressPanel("address2",
>                                new CompoundPropertyModel<Address>(
>                                                new
> AddressLoadableDetachableModel(a.getId())));
>                        item.add(ap2);
>                }
> */
>        }
> };
>
> My only solution currently is that I convert the list of addresses to a list
> of address tuples (pairs), so that I am able to repeat over pairs of
> addresses. In short, I am just wondering if there is a better way to do this
> rather than (pseudocode):
>
> List<Address> addresses = myRepository.loadAddressList();
> List<Tuple<Address,Address>> addressPairs = convertToPairs(addresses);
> // Make the above repeater iterate over "List<Tuple<Address,Address>>"
> having access
> // to two addresses per repetition
>
> Any pointers on this? Thank you in advance.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Table repeater: repeat across row AND column

Igor Vaynberg-2
In reply to this post by akarypid
see GridView

-igor

On Sun, May 1, 2011 at 9:51 AM, Alexandros Karypidis <[hidden email]> wrote:

> Hello,
>
> I am trying to create a web page that lists contact addresses in a table. My
> repeater can easily lay out one address per row, but I need to be able to
> list 2 addresses per row (actually, ideally I'd like to list N addresses per
> row). The problem is that ListView's operation [populateItem()] only
> provides you with one item to work with. So with this markup:
>
> <html xmlns:wicket>
>        <body>
>                <wicket:panel>
>                        <table wicket:id="addressesTable" style="width:
> 100%;">
>                                <tr wicket:id="addresses">
>                                        <td wicket:id="address" style="width:
> 50%;"></td>
>                                        <!--
>                                                I NEED ANOTHER CELL LIKE THE
> ONE ABOVE HERE
>                                        <td wicket:id="address2"
> style="width: 50%;"></td>
>                                        -->
>                                </tr>
>                        </table>
>                </wicket:panel>
>        </body>
> </html>
>
> If I uncomment the second cell above, I need to be able to access the "next"
> item, something like:
>
> final ListView<Address> rowContainer = new ListView<Address>(
>                "addresses", model) {
>        private static final long serialVersionUID = 1L;
>
>        @Override
>        protected void populateItem(ListItem<Address> item) {
>                Address a = item.getModelObject();
>                AddressPanel ap = new AddressPanel("address",
>                        new CompoundPropertyModel<Address>(
>                                        new
> AddressLoadableDetachableModel(a.getId())));
>                item.add(ap);
> /*
> // DOES SUCH AN API EXIST?
> //
>                if (item.hasNext()) {
>                        item.next();
>                        a = item.getModelObject();
>                        AddressPanel ap2 = new AddressPanel("address2",
>                                new CompoundPropertyModel<Address>(
>                                                new
> AddressLoadableDetachableModel(a.getId())));
>                        item.add(ap2);
>                }
> */
>        }
> };
>
> My only solution currently is that I convert the list of addresses to a list
> of address tuples (pairs), so that I am able to repeat over pairs of
> addresses. In short, I am just wondering if there is a better way to do this
> rather than (pseudocode):
>
> List<Address> addresses = myRepository.loadAddressList();
> List<Tuple<Address,Address>> addressPairs = convertToPairs(addresses);
> // Make the above repeater iterate over "List<Tuple<Address,Address>>"
> having access
> // to two addresses per repetition
>
> Any pointers on this? Thank you in advance.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...