Can you just make your 1d list look like a 2d list to the ListView?

   // this make a 1d list to look like a 2d list
    class FoldingList extends AbstractList<List<String>> implements
Serializable {
        List<String> inputList;
        int width;
        int size;

        FoldingList(List<String> inputList, int width) {
            this.inputList = inputList;
            this.width = width;
            this.size = inputList.size() / width;
        }

        @Override public List<String> get(int index) {
            return inputList.subList(width*index, width*(index + 1));
        }

        @Override public int size() {
            return size;
        }
    }



public HomePage extends WebPage {
        List<String> dataList = new ArrayList<String>(Arrays.asList(new
String[]{
            "Item1", "Item2", "Item3", "Item4", "Item5", "Item6"
        }));

        FoldingList list2 = new FoldingList(dataList, 2);

        ListView listView = new ListView("columnList", list2) {
            @Override protected void populateItem(ListItem item) {
                @SuppressWarnings("unchecked")
                List<String> row = (List<String>) item.getModelObject();
                item.add(new Label("column1", row.get(0)));
                item.add(new Label("column2", row.get(1)));
            }
        };
        add(listView);
}


        <table border="1" style="border-collapse: collapse;">
            <tr wicket:id="columnList">
                <td wicket:id="column1">column1</td>
                <td wicket:id="column2">column2</td>
            </tr>
        </table>


On Mon, Mar 3, 2008 at 4:04 PM, Ryan <[EMAIL PROTECTED]> wrote:

> I'm having a hard time finding the "Wicket way" to accomplish a simple 2
> column table.
>
> I have a List<String> with: { "Item 1", "Item 2", "Item 3", "Item 4" }
>
> I have a page that looks like this:
>
> <table>
>        <tr wicket:id="list">
>                <td>
>                        <span wicket:id="label" />
>                </td>
>        </tr>
> </table>
>
> The effect I want to achieve is a 2 column table like:
> <table>
>        <tr>
>                <td>Item 1</td>
>                <td>Item 2</td>
>        </tr>
>        <tr>
>                <td>Item 3</td>
>                <td>Item 4</td>
>        </tr>
> <table>
>
> The ListView component (as expected) prints a </tr><tr> tag after each
> item. Is there a simple way to achieve what I am trying to do without
> using the grid based components that require a data provider (which is
> overkill for what I need to do)?
>
> I found ListDataProvider which I can use with GridView, but I'm still
> wondering if there is a simpler way.
>
> Thanks!
> Ryan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to