I have written some code that *seems* to work fine, but I am a little concerned over whether my approach is (a) valid and (b) optimal. I am hoping that some of the experienced Wicket programmers can provide me with some feedback.
Basically, I have a page with four panels on it that is very similar to the Gmail "contacts" page. The first panel displays a list of user groups. The second displays a list of the users in the selected group. The third and fourth contain contextual information and can be ignored for the purposes of this discussion. The basic use-case here is to click on an Ajaxified link in the one panel (such as the user groups) and have the other panels update accordingly. My approach looks something like this: The Page class just instantiates the panels and wraps each of them in a WebMarkupContainer with setOutputMarkupId(true); Nothing too interesting. The UserPanel is reasonably straight-forward. The only thing worth mentioning is that I hold a reference to userListModel so that I can ask it to detach itself when I perform an update. public class UserPanel extends Panel { @SpringBean private UserDao userDao; private UserGroup group; // A reference to the user group so I can extract bits of info from it public IModel userListModel; // A reference to my model so that I can ask it to update itself. public UserPanel(String id, final UserGroup group) { super(id); this.group = group; userListModel = new LoadableDetachableModel() { @Override protected Object load() { return userDao.findByGroup(UserPanel.this.group); } }; ListView users = new ListView("users", userListModel) { // List the users here }; The last thing I add to this class is the setGroup(Group g) accessor method that allows me to set the group when it is changed by the user. Pretty simple really and I am reasonably confident that there isn't too much wrong so far :) The next class (the GroupPanel) is a bit more complicated and this is where I feel I am on really shaky ground... It starts of pretty much the same as UserPanel... class GroupPanel extends Panel { @SpringBean private GroupDao groupDao; private Panel userPanel; // Reference to the user panel so that I can ask it to update itself. IModel userGroupListModel = new LoadableDetachableModel() { @Override protected Object load() { return userGroupDao.find(null); // Return all the groups } }; Now for the hard part... ListView groups = new ListView("groups", userGroupListModel) { @Override protected void populateItem(ListItem item) { final Group group = (Group)item.getModelObject(); Link groupSelectorLink = new AjaxFallbackLink("groupSelector", item.getModel()) { @Override public void onClick(AjaxRequestTarget target) { UserPanel panel = (UserPanel)GroupPanel.this.userPanel; // Really ugly panel.userListModel.detach(); panel.setUserGroup(group); target.addComponent(container); // "container" refers to the WMC set in the Page class } }; As I said earlier, this code seems to work fine, but I have a couple of nagging worries: 1) Is is advisable/wise to pass object references around between panels. I saw a post elsewhere on this list that mentioned it may be a bad idea because the Serialization will break these references. It doesn't seem to, but I am only a single user running on a development server at the moment. I would hate for everything to break at a later stage. If this *is* a bad practice, what is the correct way to do this? 2) Is manually calling the detach() method of the model the best way to get it to refresh when the Ajaxified link is clicked on? It seems like a bit of a bodge, but I can't think of any other way :( 3) I have passed references to my WMC containers in the constructors of my Panels (not shown in the above code). This is really ugly and I am convinced there must be a better way. I originally tried calling getParent() assuming it must refer to the component above my Panel in the component hierarchy. As it turns out, it doesn't. Can anyone give me a definitive answer on what getParent() refers to? I couldn't figure it out from the API docs :( If you got this far, thanks for reading though all this. I know it is a bit long-winded :) Any feedback will be *greatly* appreciated. -- View this message in context: http://www.nabble.com/Panel-data-interchange---concept-validation-tp22541467p22541467.html Sent from the Wicket - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org