You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Josh Kamau <jo...@gmail.com> on 2011/01/05 10:21:34 UTC

Using CheckGroup with a listview

Hi guys;

I am trying to use a CheckGroup component in a form with a ListView to
generate a list of checks. Now, everytime i reload the page, it shows all
the checkboxes checked instead of cheking only those that exist in the
model. Where am i going wrong?

I have a Project entity that has many User entities. The form in question is
for editing project, adding and removing users. I would like to load the
page with all the Users but only the ones that exist in the project are
check.. I however always shows all checkboxes as checked. I have checked the
database and the information there is correct. Where could i be going wrong?

Here is the Java Code:

private Form<Project> frmProject;
    private ListView<User> lstUsers;
    private CheckGroup chbUsers ;

    @Inject
    private ProjectDao projectDao ;

    @Inject
    private UserDao userDao;

    public ModifyUsersPanel(String id, final Project project) {
        super(id);

        System.out.println("Project has initial "
+project.getUsers().size()+ " users" );

        frmProject = new Form<Project>("frmProject", new
CompoundPropertyModel<Project>(project));
        frmProject.setOutputMarkupId(true);

        chbUsers = new CheckGroup("users");
        chbUsers.add(new AjaxFormChoiceComponentUpdatingBehavior(){

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                System.out.println("Project has "
+project.getUsers().size()+ " users" );
                projectDao.save(project);
            }

        });

        lstUsers = new ListView<User>("checkList", new
LoadableDetachableModel<List<User>>() {

            @Override
            protected List<User> load() {
                return userDao.getAllUsers();
            }
        }){

            /**
             *
             */
            private static final long serialVersionUID = 1L;

            @Override
            protected void populateItem(ListItem<User> item) {
                item.add(new Check("checkbox", item.getModel()));
                item.add(new Label("lbFirstName",
item.getModelObject().getFirstname()));
                item.add(new Label("lbLastName",
item.getModelObject().getLastname()));
            }

        };

        chbUsers.add(lstUsers);
        frmProject.add(chbUsers);

        add(frmProject);
    }

Here is the HTML markup:

<form wicket:id="frmProject">
<div id="content">
<table class="grid_list_table" wicket:id="users">
    <thead>
        <tr>
            <th style="width: 10px;"><input type="checkbox"></th>
            <th>First Name<img src="img/desc.png" class="sort"></th>
            <th>Last Name</th>
            <th style="width: 50%;"></th>
        </tr>
    </thead>
    <tbody>
        <tr class="odd" wicket:id="checkList">
            <td><input type="checkbox" checked="checked"
wicket:id="checkbox"></td>
            <td wicket:id="lbFirstName">Bob</td>
            <td wicket:id="lbLastName">Smith</td>
            <td></td>
        </tr>
    </tbody>
</table>

</div>
</form>

Any help is appreciated.

Kind regards.
Josh.

Re: Using CheckGroup with a listview

Posted by Alexander Morozov <al...@gmail.com>.
try lstUsers.setReuseItems(true)  (see ListView javadoc)

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Using-CheckGroup-with-a-listview-tp3175047p3175610.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: Using CheckGroup with a listview

Posted by Josh Kamau <jo...@gmail.com>.
ok. let me create a quickstart.

Josh.

On Wed, Jan 5, 2011 at 2:20 PM, Pedro Santos <pe...@gmail.com> wrote:

> Hi Josh, u are right, you code looks good also, can you provide an
> quickstart?
>
> On Wed, Jan 5, 2011 at 8:32 AM, Josh Kamau <jo...@gmail.com> wrote:
>
> > Pedros
> >
> > The CheckGroup component is part of a form that users
> > CompoundPropertyModel.
> > I thought i dont have to pass any thing to the constractor other than the
> > id.
> >
> > i have however changed the constructor of CheckGroup to new
> > CheckGroup("users", project.getUsers()); and it still hasnt worked. I
> have
> > also ensured that all my models override the Equals and HashCode methods.
> >
> > Josh.
> >
> >
> >
> > On Wed, Jan 5, 2011 at 1:15 PM, Pedro Santos <pe...@gmail.com>
> wrote:
> >
> > > On Wed, Jan 5, 2011 at 7:21 AM, Josh Kamau <jo...@gmail.com>
> > wrote:
> > >
> > > > Hi guys;
> > > >
> > > > I am trying to use a CheckGroup component in a form with a ListView
> to
> > > > generate a list of checks. Now, everytime i reload the page, it shows
> > all
> > > > the checkboxes checked instead of cheking only those that exist in
> the
> > > > model. Where am i going wrong?
> > > >
> > > > I have a Project entity that has many User entities. The form in
> > question
> > > > is
> > > > for editing project, adding and removing users. I would like to load
> > the
> > > > page with all the Users but only the ones that exist in the project
> are
> > > > check.. I however always shows all checkboxes as checked. I have
> > checked
> > > > the
> > > > database and the information there is correct. Where could i be going
> > > > wrong?
> > > >
> > > > Here is the Java Code:
> > > >
> > > > private Form<Project> frmProject;
> > > >    private ListView<User> lstUsers;
> > > >    private CheckGroup chbUsers ;
> > > >
> > > >    @Inject
> > > >    private ProjectDao projectDao ;
> > > >
> > > >    @Inject
> > > >    private UserDao userDao;
> > > >
> > > >    public ModifyUsersPanel(String id, final Project project) {
> > > >        super(id);
> > > >
> > > >        System.out.println("Project has initial "
> > > > +project.getUsers().size()+ " users" );
> > > >
> > > >        frmProject = new Form<Project>("frmProject", new
> > > > CompoundPropertyModel<Project>(project));
> > > >        frmProject.setOutputMarkupId(true);
> > > >
> > > >        chbUsers = new CheckGroup("users");
> > > >
> > >
> > > --> as the Check is being created as: new Check("checkbox",
> > > item.getModel())
> > > you need to specify the selected users collection to CheckGroup, you
> can
> > > pass it as parameter
> > >
> > >
> > > >        chbUsers.add(new AjaxFormChoiceComponentUpdatingBehavior(){
> > > >
> > > >            @Override
> > > >            protected void onUpdate(AjaxRequestTarget target) {
> > > >                System.out.println("Project has "
> > > > +project.getUsers().size()+ " users" );
> > > >                projectDao.save(project);
> > > >            }
> > > >
> > > >        });
> > > >
> > > >        lstUsers = new ListView<User>("checkList", new
> > > > LoadableDetachableModel<List<User>>() {
> > > >
> > > >            @Override
> > > >            protected List<User> load() {
> > > >                return userDao.getAllUsers();
> > > >            }
> > > >        }){
> > > >
> > > >            /**
> > > >             *
> > > >             */
> > > >            private static final long serialVersionUID = 1L;
> > > >
> > > >            @Override
> > > >            protected void populateItem(ListItem<User> item) {
> > > >                item.add(new Check("checkbox", item.getModel()));
> > > >                item.add(new Label("lbFirstName",
> > > > item.getModelObject().getFirstname()));
> > > >                item.add(new Label("lbLastName",
> > > > item.getModelObject().getLastname()));
> > > >            }
> > > >
> > > >        };
> > > >
> > > >        chbUsers.add(lstUsers);
> > > >        frmProject.add(chbUsers);
> > > >
> > > >        add(frmProject);
> > > >    }
> > > >
> > > > Here is the HTML markup:
> > > >
> > > > <form wicket:id="frmProject">
> > > > <div id="content">
> > > > <table class="grid_list_table" wicket:id="users">
> > > >    <thead>
> > > >        <tr>
> > > >            <th style="width: 10px;"><input type="checkbox"></th>
> > > >            <th>First Name<img src="img/desc.png" class="sort"></th>
> > > >            <th>Last Name</th>
> > > >            <th style="width: 50%;"></th>
> > > >        </tr>
> > > >    </thead>
> > > >    <tbody>
> > > >        <tr class="odd" wicket:id="checkList">
> > > >            <td><input type="checkbox" checked="checked"
> > > > wicket:id="checkbox"></td>
> > > >            <td wicket:id="lbFirstName">Bob</td>
> > > >            <td wicket:id="lbLastName">Smith</td>
> > > >            <td></td>
> > > >        </tr>
> > > >    </tbody>
> > > > </table>
> > > >
> > > > </div>
> > > > </form>
> > > >
> > > > Any help is appreciated.
> > > >
> > > > Kind regards.
> > > > Josh.
> > > >
> > >
> > >
> > >
> > > --
> > > Pedro Henrique Oliveira dos Santos
> > >
> >
>
>
>
> --
> Pedro Henrique Oliveira dos Santos
>

Re: Using CheckGroup with a listview

Posted by Pedro Santos <pe...@gmail.com>.
Hi Josh, u are right, you code looks good also, can you provide an
quickstart?

On Wed, Jan 5, 2011 at 8:32 AM, Josh Kamau <jo...@gmail.com> wrote:

> Pedros
>
> The CheckGroup component is part of a form that users
> CompoundPropertyModel.
> I thought i dont have to pass any thing to the constractor other than the
> id.
>
> i have however changed the constructor of CheckGroup to new
> CheckGroup("users", project.getUsers()); and it still hasnt worked. I have
> also ensured that all my models override the Equals and HashCode methods.
>
> Josh.
>
>
>
> On Wed, Jan 5, 2011 at 1:15 PM, Pedro Santos <pe...@gmail.com> wrote:
>
> > On Wed, Jan 5, 2011 at 7:21 AM, Josh Kamau <jo...@gmail.com>
> wrote:
> >
> > > Hi guys;
> > >
> > > I am trying to use a CheckGroup component in a form with a ListView to
> > > generate a list of checks. Now, everytime i reload the page, it shows
> all
> > > the checkboxes checked instead of cheking only those that exist in the
> > > model. Where am i going wrong?
> > >
> > > I have a Project entity that has many User entities. The form in
> question
> > > is
> > > for editing project, adding and removing users. I would like to load
> the
> > > page with all the Users but only the ones that exist in the project are
> > > check.. I however always shows all checkboxes as checked. I have
> checked
> > > the
> > > database and the information there is correct. Where could i be going
> > > wrong?
> > >
> > > Here is the Java Code:
> > >
> > > private Form<Project> frmProject;
> > >    private ListView<User> lstUsers;
> > >    private CheckGroup chbUsers ;
> > >
> > >    @Inject
> > >    private ProjectDao projectDao ;
> > >
> > >    @Inject
> > >    private UserDao userDao;
> > >
> > >    public ModifyUsersPanel(String id, final Project project) {
> > >        super(id);
> > >
> > >        System.out.println("Project has initial "
> > > +project.getUsers().size()+ " users" );
> > >
> > >        frmProject = new Form<Project>("frmProject", new
> > > CompoundPropertyModel<Project>(project));
> > >        frmProject.setOutputMarkupId(true);
> > >
> > >        chbUsers = new CheckGroup("users");
> > >
> >
> > --> as the Check is being created as: new Check("checkbox",
> > item.getModel())
> > you need to specify the selected users collection to CheckGroup, you can
> > pass it as parameter
> >
> >
> > >        chbUsers.add(new AjaxFormChoiceComponentUpdatingBehavior(){
> > >
> > >            @Override
> > >            protected void onUpdate(AjaxRequestTarget target) {
> > >                System.out.println("Project has "
> > > +project.getUsers().size()+ " users" );
> > >                projectDao.save(project);
> > >            }
> > >
> > >        });
> > >
> > >        lstUsers = new ListView<User>("checkList", new
> > > LoadableDetachableModel<List<User>>() {
> > >
> > >            @Override
> > >            protected List<User> load() {
> > >                return userDao.getAllUsers();
> > >            }
> > >        }){
> > >
> > >            /**
> > >             *
> > >             */
> > >            private static final long serialVersionUID = 1L;
> > >
> > >            @Override
> > >            protected void populateItem(ListItem<User> item) {
> > >                item.add(new Check("checkbox", item.getModel()));
> > >                item.add(new Label("lbFirstName",
> > > item.getModelObject().getFirstname()));
> > >                item.add(new Label("lbLastName",
> > > item.getModelObject().getLastname()));
> > >            }
> > >
> > >        };
> > >
> > >        chbUsers.add(lstUsers);
> > >        frmProject.add(chbUsers);
> > >
> > >        add(frmProject);
> > >    }
> > >
> > > Here is the HTML markup:
> > >
> > > <form wicket:id="frmProject">
> > > <div id="content">
> > > <table class="grid_list_table" wicket:id="users">
> > >    <thead>
> > >        <tr>
> > >            <th style="width: 10px;"><input type="checkbox"></th>
> > >            <th>First Name<img src="img/desc.png" class="sort"></th>
> > >            <th>Last Name</th>
> > >            <th style="width: 50%;"></th>
> > >        </tr>
> > >    </thead>
> > >    <tbody>
> > >        <tr class="odd" wicket:id="checkList">
> > >            <td><input type="checkbox" checked="checked"
> > > wicket:id="checkbox"></td>
> > >            <td wicket:id="lbFirstName">Bob</td>
> > >            <td wicket:id="lbLastName">Smith</td>
> > >            <td></td>
> > >        </tr>
> > >    </tbody>
> > > </table>
> > >
> > > </div>
> > > </form>
> > >
> > > Any help is appreciated.
> > >
> > > Kind regards.
> > > Josh.
> > >
> >
> >
> >
> > --
> > Pedro Henrique Oliveira dos Santos
> >
>



-- 
Pedro Henrique Oliveira dos Santos

Re: Using CheckGroup with a listview

Posted by Josh Kamau <jo...@gmail.com>.
Pedros

The CheckGroup component is part of a form that users CompoundPropertyModel.
I thought i dont have to pass any thing to the constractor other than the
id.

i have however changed the constructor of CheckGroup to new
CheckGroup("users", project.getUsers()); and it still hasnt worked. I have
also ensured that all my models override the Equals and HashCode methods.

Josh.



On Wed, Jan 5, 2011 at 1:15 PM, Pedro Santos <pe...@gmail.com> wrote:

> On Wed, Jan 5, 2011 at 7:21 AM, Josh Kamau <jo...@gmail.com> wrote:
>
> > Hi guys;
> >
> > I am trying to use a CheckGroup component in a form with a ListView to
> > generate a list of checks. Now, everytime i reload the page, it shows all
> > the checkboxes checked instead of cheking only those that exist in the
> > model. Where am i going wrong?
> >
> > I have a Project entity that has many User entities. The form in question
> > is
> > for editing project, adding and removing users. I would like to load the
> > page with all the Users but only the ones that exist in the project are
> > check.. I however always shows all checkboxes as checked. I have checked
> > the
> > database and the information there is correct. Where could i be going
> > wrong?
> >
> > Here is the Java Code:
> >
> > private Form<Project> frmProject;
> >    private ListView<User> lstUsers;
> >    private CheckGroup chbUsers ;
> >
> >    @Inject
> >    private ProjectDao projectDao ;
> >
> >    @Inject
> >    private UserDao userDao;
> >
> >    public ModifyUsersPanel(String id, final Project project) {
> >        super(id);
> >
> >        System.out.println("Project has initial "
> > +project.getUsers().size()+ " users" );
> >
> >        frmProject = new Form<Project>("frmProject", new
> > CompoundPropertyModel<Project>(project));
> >        frmProject.setOutputMarkupId(true);
> >
> >        chbUsers = new CheckGroup("users");
> >
>
> --> as the Check is being created as: new Check("checkbox",
> item.getModel())
> you need to specify the selected users collection to CheckGroup, you can
> pass it as parameter
>
>
> >        chbUsers.add(new AjaxFormChoiceComponentUpdatingBehavior(){
> >
> >            @Override
> >            protected void onUpdate(AjaxRequestTarget target) {
> >                System.out.println("Project has "
> > +project.getUsers().size()+ " users" );
> >                projectDao.save(project);
> >            }
> >
> >        });
> >
> >        lstUsers = new ListView<User>("checkList", new
> > LoadableDetachableModel<List<User>>() {
> >
> >            @Override
> >            protected List<User> load() {
> >                return userDao.getAllUsers();
> >            }
> >        }){
> >
> >            /**
> >             *
> >             */
> >            private static final long serialVersionUID = 1L;
> >
> >            @Override
> >            protected void populateItem(ListItem<User> item) {
> >                item.add(new Check("checkbox", item.getModel()));
> >                item.add(new Label("lbFirstName",
> > item.getModelObject().getFirstname()));
> >                item.add(new Label("lbLastName",
> > item.getModelObject().getLastname()));
> >            }
> >
> >        };
> >
> >        chbUsers.add(lstUsers);
> >        frmProject.add(chbUsers);
> >
> >        add(frmProject);
> >    }
> >
> > Here is the HTML markup:
> >
> > <form wicket:id="frmProject">
> > <div id="content">
> > <table class="grid_list_table" wicket:id="users">
> >    <thead>
> >        <tr>
> >            <th style="width: 10px;"><input type="checkbox"></th>
> >            <th>First Name<img src="img/desc.png" class="sort"></th>
> >            <th>Last Name</th>
> >            <th style="width: 50%;"></th>
> >        </tr>
> >    </thead>
> >    <tbody>
> >        <tr class="odd" wicket:id="checkList">
> >            <td><input type="checkbox" checked="checked"
> > wicket:id="checkbox"></td>
> >            <td wicket:id="lbFirstName">Bob</td>
> >            <td wicket:id="lbLastName">Smith</td>
> >            <td></td>
> >        </tr>
> >    </tbody>
> > </table>
> >
> > </div>
> > </form>
> >
> > Any help is appreciated.
> >
> > Kind regards.
> > Josh.
> >
>
>
>
> --
> Pedro Henrique Oliveira dos Santos
>

Re: Using CheckGroup with a listview

Posted by Pedro Santos <pe...@gmail.com>.
On Wed, Jan 5, 2011 at 7:21 AM, Josh Kamau <jo...@gmail.com> wrote:

> Hi guys;
>
> I am trying to use a CheckGroup component in a form with a ListView to
> generate a list of checks. Now, everytime i reload the page, it shows all
> the checkboxes checked instead of cheking only those that exist in the
> model. Where am i going wrong?
>
> I have a Project entity that has many User entities. The form in question
> is
> for editing project, adding and removing users. I would like to load the
> page with all the Users but only the ones that exist in the project are
> check.. I however always shows all checkboxes as checked. I have checked
> the
> database and the information there is correct. Where could i be going
> wrong?
>
> Here is the Java Code:
>
> private Form<Project> frmProject;
>    private ListView<User> lstUsers;
>    private CheckGroup chbUsers ;
>
>    @Inject
>    private ProjectDao projectDao ;
>
>    @Inject
>    private UserDao userDao;
>
>    public ModifyUsersPanel(String id, final Project project) {
>        super(id);
>
>        System.out.println("Project has initial "
> +project.getUsers().size()+ " users" );
>
>        frmProject = new Form<Project>("frmProject", new
> CompoundPropertyModel<Project>(project));
>        frmProject.setOutputMarkupId(true);
>
>        chbUsers = new CheckGroup("users");
>

--> as the Check is being created as: new Check("checkbox", item.getModel())
you need to specify the selected users collection to CheckGroup, you can
pass it as parameter


>        chbUsers.add(new AjaxFormChoiceComponentUpdatingBehavior(){
>
>            @Override
>            protected void onUpdate(AjaxRequestTarget target) {
>                System.out.println("Project has "
> +project.getUsers().size()+ " users" );
>                projectDao.save(project);
>            }
>
>        });
>
>        lstUsers = new ListView<User>("checkList", new
> LoadableDetachableModel<List<User>>() {
>
>            @Override
>            protected List<User> load() {
>                return userDao.getAllUsers();
>            }
>        }){
>
>            /**
>             *
>             */
>            private static final long serialVersionUID = 1L;
>
>            @Override
>            protected void populateItem(ListItem<User> item) {
>                item.add(new Check("checkbox", item.getModel()));
>                item.add(new Label("lbFirstName",
> item.getModelObject().getFirstname()));
>                item.add(new Label("lbLastName",
> item.getModelObject().getLastname()));
>            }
>
>        };
>
>        chbUsers.add(lstUsers);
>        frmProject.add(chbUsers);
>
>        add(frmProject);
>    }
>
> Here is the HTML markup:
>
> <form wicket:id="frmProject">
> <div id="content">
> <table class="grid_list_table" wicket:id="users">
>    <thead>
>        <tr>
>            <th style="width: 10px;"><input type="checkbox"></th>
>            <th>First Name<img src="img/desc.png" class="sort"></th>
>            <th>Last Name</th>
>            <th style="width: 50%;"></th>
>        </tr>
>    </thead>
>    <tbody>
>        <tr class="odd" wicket:id="checkList">
>            <td><input type="checkbox" checked="checked"
> wicket:id="checkbox"></td>
>            <td wicket:id="lbFirstName">Bob</td>
>            <td wicket:id="lbLastName">Smith</td>
>            <td></td>
>        </tr>
>    </tbody>
> </table>
>
> </div>
> </form>
>
> Any help is appreciated.
>
> Kind regards.
> Josh.
>



-- 
Pedro Henrique Oliveira dos Santos