You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jeff Palmer <jp...@citytechinc.com> on 2009/04/06 22:57:43 UTC

Updating form components in list view

I have a list view that has some form components (a checkbox and a RadioChoice). All of the data from the ListView is getting displayed on the page properly, but when I try to modify one of the form values, it isn't getting updated as expected. If anyone has any idea what I might be doing wrong, please let me know. I have pasted the contents of my code below.

public class MaintainUsersPage extends EzdecBaseWebPage {

    @SpringBean
    private ISecurityRepository securityRepository;

    @SpringBean
    private ISecurityService securityService;

    private EzdecAccount account;

    public class UsersModel extends LoadableDetachableModel {
        private EzdecAccount account;

        public UsersModel(EzdecAccount account) {
            this.account = account;
        }

        @Override
        protected Object load() {
            List<EzdecUser> users = securityRepository.findAllNonArchivedUsersByAccount(account);
            return users;
        }
    }

public MaintainUsersPage() {
        add(new FeedbackPanel("feedback"));
       
        account = EzdecSession.getCurrentUser().getAccount();

        add(new BookmarkablePageLink("inviteUserLink", InviteUser.class));

        add(new Label("accountName", new PropertyModel(account, "name")));
 
        Form form = new Form("maintainUsersForm");
        PageableListView users = new PageableListView("users", new UsersModel(account), 20) {

            @Override
            protected void populateItem(final ListItem item) {
                if (item.getIndex() % 2 == 0) {
                    item.add(new SimpleAttributeModifier("class", "odd"));
                }
                final EzdecUser user = (EzdecUser) item.getModelObject();
                Link nameLink = new Link("nameLink") {
                    @Override
                    public void onClick() {
                        setResponsePage(new UpdateUserProfilePage(user));
                    }
                };
                nameLink.add(new Label("fullname", user.getFullname()));
                item.add(nameLink);
                item.add(new ExternalLink("emailLink", "mailto:" + user.getEmail()).add(new Label("email", user.getEmail())));
                item.add(new CheckBox("active", new PropertyModel(user, "active")));
                item.add(new RadioChoice("roles",
                         new PropertyModel(user, "roles"),
                         Arrays.asList(EzdecRole.values())));
                Link deleteLink = new Link("delete") {
                    @Override
                    public void onClick() {
                        if (securityService.archiveUser(user)) {
                            EzdecSession.get().info("User " + user.getFullname() + " has been deleted.");
                            setResponsePage(MaintainUsersPage.class);
                        } else {
                            EzdecSession.get().info("User " + user.getFullname() +
                                " could not be be deleted. Please ensure that you " +
                                " are an account administrator and that you are " +
                                " not trying to delete your own account.");
                            setResponsePage(MaintainUsersPage.class);
                        }
                    }
                };
                deleteLink.add(new SimpleAttributeModifier("onclick",
                        "return confirm('Are you sure?');"));
                item.add(deleteLink);

                Link submitLink = new Link("submitLink") {
                    @Override
                    public void onClick() {
                        if (securityService.updateUser(user)) {
                            EzdecSession.get().info("User " + user.getFullname() + " has been updated.");
                            setResponsePage(MaintainUsersPage.class);
                        } else {
                            EzdecSession.get().info("User " + user.getFullname() + " has not been updated.");
                            setResponsePage(MaintainUsersPage.class);
                        }
                    }
                };
                item.add(submitLink);
            }          
        };

        form.add(users);
        add(form);
        add(new PagingNavigator("navigator", users));
    }
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Updating form components in list view

Posted by Ryan Gravener <ry...@ryangravener.com>.
have you tried ListView#setReuseItems(true) ?

Ryan Gravener
http://ryangravener.com/flex | http://twitter.com/ryangravener


On Mon, Apr 6, 2009 at 4:57 PM, Jeff Palmer <jp...@citytechinc.com> wrote:

> I have a list view that has some form components (a checkbox and a
> RadioChoice). All of the data from the ListView is getting displayed on the
> page properly, but when I try to modify one of the form values, it isn't
> getting updated as expected. If anyone has any idea what I might be doing
> wrong, please let me know. I have pasted the contents of my code below.
>
> public class MaintainUsersPage extends EzdecBaseWebPage {
>
>    @SpringBean
>    private ISecurityRepository securityRepository;
>
>    @SpringBean
>    private ISecurityService securityService;
>
>    private EzdecAccount account;
>
>    public class UsersModel extends LoadableDetachableModel {
>        private EzdecAccount account;
>
>        public UsersModel(EzdecAccount account) {
>            this.account = account;
>        }
>
>        @Override
>        protected Object load() {
>            List<EzdecUser> users =
> securityRepository.findAllNonArchivedUsersByAccount(account);
>            return users;
>        }
>    }
>
> public MaintainUsersPage() {
>        add(new FeedbackPanel("feedback"));
>
>        account = EzdecSession.getCurrentUser().getAccount();
>
>        add(new BookmarkablePageLink("inviteUserLink", InviteUser.class));
>
>        add(new Label("accountName", new PropertyModel(account, "name")));
>
>        Form form = new Form("maintainUsersForm");
>        PageableListView users = new PageableListView("users", new
> UsersModel(account), 20) {
>
>            @Override
>            protected void populateItem(final ListItem item) {
>                if (item.getIndex() % 2 == 0) {
>                    item.add(new SimpleAttributeModifier("class", "odd"));
>                }
>                final EzdecUser user = (EzdecUser) item.getModelObject();
>                Link nameLink = new Link("nameLink") {
>                    @Override
>                    public void onClick() {
>                        setResponsePage(new UpdateUserProfilePage(user));
>                    }
>                };
>                nameLink.add(new Label("fullname", user.getFullname()));
>                item.add(nameLink);
>                item.add(new ExternalLink("emailLink", "mailto:" +
> user.getEmail()).add(new Label("email", user.getEmail())));
>                item.add(new CheckBox("active", new PropertyModel(user,
> "active")));
>                item.add(new RadioChoice("roles",
>                         new PropertyModel(user, "roles"),
>                         Arrays.asList(EzdecRole.values())));
>                Link deleteLink = new Link("delete") {
>                    @Override
>                    public void onClick() {
>                        if (securityService.archiveUser(user)) {
>                            EzdecSession.get().info("User " +
> user.getFullname() + " has been deleted.");
>                            setResponsePage(MaintainUsersPage.class);
>                        } else {
>                            EzdecSession.get().info("User " +
> user.getFullname() +
>                                " could not be be deleted. Please ensure
> that you " +
>                                " are an account administrator and that you
> are " +
>                                " not trying to delete your own account.");
>                            setResponsePage(MaintainUsersPage.class);
>                        }
>                    }
>                };
>                deleteLink.add(new SimpleAttributeModifier("onclick",
>                        "return confirm('Are you sure?');"));
>                item.add(deleteLink);
>
>                Link submitLink = new Link("submitLink") {
>                    @Override
>                    public void onClick() {
>                        if (securityService.updateUser(user)) {
>                            EzdecSession.get().info("User " +
> user.getFullname() + " has been updated.");
>                            setResponsePage(MaintainUsersPage.class);
>                        } else {
>                            EzdecSession.get().info("User " +
> user.getFullname() + " has not been updated.");
>                            setResponsePage(MaintainUsersPage.class);
>                        }
>                    }
>                };
>                item.add(submitLink);
>            }
>        };
>
>        form.add(users);
>        add(form);
>        add(new PagingNavigator("navigator", users));
>    }
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>