I believe this is a variable reference issue. // instead of this.... isbnField.add(new AjaxFormComponentUpdatingBehavior("onchange") {...@override protected void onUpdate(final AjaxRequestTarget target) {try {book = bookRetriever.getBook(isbnField.getInput()); // try this....@overrideprotected void onUpdate(final AjaxRequestTarget target) {try {book = bookRetriever.getBook(isbnField.getInput());setDefaultModel(new CompoundPropertyModel<Book>(book));modelChanged(); When you passed in book to the constructor, it now has a reference to your book object, when you execute this line: book = bookRetriever.getBook(isbnField.getInput());
you are only changing the value of the variable book, but not the reference stored in new CompoundPropertyModel<Book>(book). You should be able pull that off in C++ by changing the value of the pointer, but you can't do that in java. It is similar to this short code String y = "example";java.util.HashMap h = new java.util.HashMap();h.put("y",y);// changing the value of y y="not you";// see that the value of y is not the same as the reference we stored in the hashmapSystem.out.println(h.get("y"));System.out.println(y); I hope that helps. Russ > Date: Thu, 13 Aug 2009 09:15:50 +0200 > From: lvd...@heritageagenturen.nl > To: users@wicket.apache.org > Subject: Re: Ajax based filling of form > > Well the model doesn't update. (Not that I'd expect it to.) > > Here's some pieces of my code I deem relevant to the problem. > > > if (key == null || key.getIsbn() == null) { > book = new Book(); > } else { > book = bookRetriever.getBook(key.getIsbn(), key.getCollectionId()); > } > > setDefaultModel(new CompoundPropertyModel<Book>(book)); > > // ... > > isbnField.add(new AjaxFormComponentUpdatingBehavior("onchange") { > private static final long serialVersionUID = 1L; > > @Override > protected void onUpdate(final AjaxRequestTarget target) { > try { > book = bookRetriever.getBook(isbnField.getInput()); > modelChanged(); > > target.addComponent(titleField); > //... > target.addComponent(genrefield); > } catch (SQLException e) { > //... > } > } > }); > > John Krasnay wrote: > > Sounds like you're on the right track. What's the problem? > > > > jk > > > > On Wed, Aug 12, 2009 at 04:27:41PM +0200, Linda van der Pal wrote: > > > >> I have a panel with a form. This form has several fields, one of which > >> is the ISBN of a book. The fields are filled by a CompoundPropertyModel > >> if the user is editing his previous entry, and they are empty if the > >> user is adding a new book. Simply entering data or updating it and then > >> submitting already works. But now I want to fetch the data for the other > >> fields if the ISBN is already in the database. It is a multi-user > >> system, so it is in fact possible that the ISBN is already in there. > >> > >> I was thinking of achieving this with AJAX, but I'm not really sure how > >> to do it. I was thinking of adding an AjaxFormComponentUpdatingBeavior, > >> where all the related fields are added to the target. But as the ISBN is > >> part of the model, I don't really now how to get this working. Any hints > >> on what direction I should be searching in? > >> > >> Regards, > >> Linda > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > >> For additional commands, e-mail: users-h...@wicket.apache.org > >> > >> > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > > For additional commands, e-mail: users-h...@wicket.apache.org > > > > ------------------------------------------------------------------------ > > > > > > No virus found in this incoming message. > > Checked by AVG - www.avg.com > > Version: 8.5.392 / Virus Database: 270.13.53/2299 - Release Date: 08/12/09 > > 18:12:00 > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > _________________________________________________________________ Get back to school stuff for them and cashback for you. http://www.bing.com/cashback?form=MSHYCB&publ=WLHMTAG&crea=TEXT_MSHYCB_BackToSchool_Cashback_BTSCashback_1x1