You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ryan <wi...@mandrake.us> on 2008/03/04 01:04:26 UTC

Simple table with ListView

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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Simple table with ListView

Posted by Ryan <wi...@mandrake.us>.
On Mon, Mar 03, 2008 at 07:27:41PM -0800, Gin Yeah exclaimed:

>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>
>



This looks like it will work as well. Thanks for the idea.

-Ryan

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


Re: Simple table with ListView

Posted by Gin Yeah <gi...@gmail.com>.
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 <wi...@mandrake.us> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Simple table with ListView

Posted by Ryan <wi...@mandrake.us>.
That is my next move, I was just wondering if there was a simpler way.

Looking at that example code, its already looks really simple - I was
just being lazy.

Thanks!
Ryan

On Mon, Mar 03, 2008 at 07:10:07PM -0500, James Carman exclaimed:

>Have you tried GridView?  There's a good example here:
>
>http://www.wicketstuff.org/wicket13/repeater/
>
>
>On 3/3/08, Ryan <wi...@mandrake.us> 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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Simple table with ListView

Posted by James Carman <ja...@carmanconsulting.com>.
Have you tried GridView?  There's a good example here:

http://www.wicketstuff.org/wicket13/repeater/


On 3/3/08, Ryan <wi...@mandrake.us> 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: 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