You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "x.yang" <x....@talk21.com> on 2012/01/19 07:49:53 UTC

ListView not refreshed after a new row is inserted with EJB3 as its backend data

Hello, Everyone,

I am trying to build a web app with Wicket, EJB3, and MySQL. My IDE is
Netbeans 6.9.1 and the server is Glassfish 3.1. 

I have created two entity beans 'Centre' and 'User', and one Centre has many
User(s). I also created two Facades for them.

The Wicket page used to list the Users is as below:

<------------------------------------------------------------
class ListUsers extends WebPage {

    @EJB(name = "UserFacade")
    private UserFacade userFacade;

    public ListUsers(Centre c) {
        List<User> users;
        if (c == null) {
            users = userFacade.findAll();
        } else {
            users = new ArrayList<User>(c.getUserCollection());
        }
        final ListView<User> list = new ListView<User>("eachUser", users) {

            @Override
            protected void populateItem(ListItem item) {
                final User user = (User) item.getModelObject();
                item.add(new Label("username", user.getUsername()));
                item.add(new Label("fullname", user.getFullname()));
                item.add(new Label("email", user.getEmail()));
                item.add(new Label("centreid", user.getCentre().getName()));
            }
        };
        add(list);
    }
}
----------------------------------------------------->

The page to add a User is following:

<----------------------------------------------------
    public AddUser(Centre c) {
        user = new User();
        user.setCentre(c);
        Form<AddUser> form = new Form<AddUser>("AddUser") {

            @Override
            protected void onSubmit() {
                userFacade.create(user);
            }
        };

        form.add(new TextField<String>("username",
                new PropertyModel(user, "username")).setRequired(true));

        PasswordTextField tf_password = new PasswordTextField("password",
                new PropertyModel(user, "hashedPassword"));
        form.add(tf_password);

        form.add(new TextField<String>("fullname",
                new PropertyModel(user, "fullname")).setRequired(true));

        TextField tf_email = new TextField<String>("email",
                new PropertyModel(user, "email"));
        form.add(tf_email);

        LoadableDetachableModel centres = new LoadableDetachableModel() {

            @Override
            protected Object load() {
                return centreFacade.findAll();
            }
        };
        DropDownChoice<Centre> ddc = new DropDownChoice<Centre>("centreid",
                new PropertyModel<Centre>(user, "centre"), centres,
                new ChoiceRenderer<Centre>("name", "name"));

        form.add(ddc.setRequired(true));

        add(form);
    }
}

-------------------------------------------------------->

The problem is I can't see the newly added User in the list with
getUserCollection() method of Centre, but I do see the new User if I use
userFacade.findAll() method. Could you please help me and point me to the
right direction? I am quite new to Wicket and EJB3. Any comments are welcom.
Thanks a lot.

Yang



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListView-not-refreshed-after-a-new-row-is-inserted-with-EJB3-as-its-backend-data-tp4309318p4309318.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: ListView not refreshed after a new row is inserted with EJB3 as its backend data

Posted by Per Newgro <pe...@gmx.ch>.
Use a LoadableDetachableModel<List<User>> in the ListView Constructor.
Put all the load loading into the load method and see what happens.

Cheers
Per

Am 19.01.2012 07:49, schrieb x.yang:
> Hello, Everyone,
>
> I am trying to build a web app with Wicket, EJB3, and MySQL. My IDE is
> Netbeans 6.9.1 and the server is Glassfish 3.1.
>
> I have created two entity beans 'Centre' and 'User', and one Centre has many
> User(s). I also created two Facades for them.
>
> The Wicket page used to list the Users is as below:
>
> <------------------------------------------------------------
> class ListUsers extends WebPage {
>
>      @EJB(name = "UserFacade")
>      private UserFacade userFacade;
>
>      public ListUsers(Centre c) {
>          List<User>  users;
>          if (c == null) {
>              users = userFacade.findAll();
>          } else {
>              users = new ArrayList<User>(c.getUserCollection());
>          }
>          final ListView<User>  list = new ListView<User>("eachUser", users) {
>
>              @Override
>              protected void populateItem(ListItem item) {
>                  final User user = (User) item.getModelObject();
>                  item.add(new Label("username", user.getUsername()));
>                  item.add(new Label("fullname", user.getFullname()));
>                  item.add(new Label("email", user.getEmail()));
>                  item.add(new Label("centreid", user.getCentre().getName()));
>              }
>          };
>          add(list);
>      }
> }
> ----------------------------------------------------->
>
> The page to add a User is following:
>
> <----------------------------------------------------
>      public AddUser(Centre c) {
>          user = new User();
>          user.setCentre(c);
>          Form<AddUser>  form = new Form<AddUser>("AddUser") {
>
>              @Override
>              protected void onSubmit() {
>                  userFacade.create(user);
>              }
>          };
>
>          form.add(new TextField<String>("username",
>                  new PropertyModel(user, "username")).setRequired(true));
>
>          PasswordTextField tf_password = new PasswordTextField("password",
>                  new PropertyModel(user, "hashedPassword"));
>          form.add(tf_password);
>
>          form.add(new TextField<String>("fullname",
>                  new PropertyModel(user, "fullname")).setRequired(true));
>
>          TextField tf_email = new TextField<String>("email",
>                  new PropertyModel(user, "email"));
>          form.add(tf_email);
>
>          LoadableDetachableModel centres = new LoadableDetachableModel() {
>
>              @Override
>              protected Object load() {
>                  return centreFacade.findAll();
>              }
>          };
>          DropDownChoice<Centre>  ddc = new DropDownChoice<Centre>("centreid",
>                  new PropertyModel<Centre>(user, "centre"), centres,
>                  new ChoiceRenderer<Centre>("name", "name"));
>
>          form.add(ddc.setRequired(true));
>
>          add(form);
>      }
> }
>
> -------------------------------------------------------->
>
> The problem is I can't see the newly added User in the list with
> getUserCollection() method of Centre, but I do see the new User if I use
> userFacade.findAll() method. Could you please help me and point me to the
> right direction? I am quite new to Wicket and EJB3. Any comments are welcom.
> Thanks a lot.
>
> Yang
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListView-not-refreshed-after-a-new-row-is-inserted-with-EJB3-as-its-backend-data-tp4309318p4309318.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
>
>


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