Search code examples
wicketwicket-6wicket-1.6

Wicket form with list of all available values


Suppose we have following entities (representing a m:n relation, with additional column on the join table):

public class User {
    private String name;
    private List<Login> logins;
}

public class Login {
   private User user;
   private Website website;
   private String login;
}

public class Website {
   private String name;
   private List<Login> logins;
}

I want to create a User edit form that contains one login input field per each existing website (so that all existing websites are in the form). E.g., having 2 websites defined (website1, website2), I would like to see:

form

My problem is with achieving following behavior on submission of the form: if login input field is filled for a website, it should be added to user1's logins, and if it's empty, it should not be added/get removed.

I created the form using User model (for user name), and website's fields use ListView backed by a model of all logins (taken straight from DB). This makes my form look as expected, but the behaviour is not there, as websites model is independent from the User model. What is your recommended approach?


Solution

  • Changing ListView to PropertyListView did the trick. Model gets updated properly and therefore I can do any required postprocessing in onSubmit(). With the ListView, form was rendered fine, but changes in login input fields were ignored.