The problem is that I can't seem to access the form submitted values in onSubmit().
ValueMap values = getModelObject(); values is null... Daniel On Mon, Jan 23, 2012 at 9:24 AM, Sven Meier <[email protected]> wrote: > So you're already using PropertyListView, fine. > > What's your problem once again? > > Sven > > > Am 23.01.2012 17:20, schrieb Daniel Watrous: >> >> Let me give a little more detail. The way that markup is managed is >> through this: >> >> // Add movieListView of existing movies >> moviesForm.add(new PropertyListView<Movie>("movies", movieList) { >> >> @Override >> public void populateItem(final ListItem<Movie> movieItem) { >> final RatingModel rating = new >> RatingModel(movieItem.getModelObject().getRating()); >> movieItem.add(new >> TextField<String>("name").setType(String.class)); >> movieItem.add(new DropDownChoice<Category>("category", >> Arrays.asList(Category.values()), new >> EnumChoiceRenderer<Category>(this))); >> movieItem.add(new RatingPanel ("rating", new >> PropertyModel<Integer>(rating, "rating"), 5, new >> PropertyModel<Integer>(rating, "numberOfVotes"), false) { >> @Override >> public boolean onIsStarActive(int star) { >> return rating.isActive(star); >> } >> @Override >> public void onRated(int newRating, >> AjaxRequestTarget target) { >> movieItem.getModelObject().setRating(newRating); >> rating.updateRating(newRating); >> >> Session session = >> HibernateUtil.getSessionFactory().getCurrentSession(); >> session.beginTransaction(); >> session.update(movieItem.getModelObject()); >> session.getTransaction().commit(); >> >> movieList.detach(); >> } >> }); >> movieItem.add(new Link("removeLink") { >> @Override >> public void onClick() { >> >> System.out.print(movieItem.getModelObject().getId()); >> Session session = >> HibernateUtil.getSessionFactory().getCurrentSession(); >> session.beginTransaction(); >> session.delete(movieItem.getModelObject()); >> session.getTransaction().commit(); >> movieList.detach(); >> } >> }); >> } >> }).setVersioned(false); >> >> I suppose that means that I'm not actually adding new items to the >> list as a form. Maybe what I need is to treat the entire component as >> a form from the beginning. I'm just not sure exactly how to do that. >> >> Any ideas? >> >> Daniel >> >> On Mon, Jan 23, 2012 at 9:07 AM, Daniel Watrous >> <[email protected]> wrote: >>> >>> I have populated a form with values representing several different >>> objects. This is what my markup looks like: >>> >>> >>> <form wicket:id = "moviesForm" id = "moviesForm"> >>> <span wicket:id = "movies" id = "movies"> >>> <a wicket:id = "removeLink">(remove)</a> >>> <input type="text" wicket:id="name" class="nospam"/> >>> <select wicket:id="category"/> >>> <span wicket:id="rating">rating</span> >>> <br /> >>> </span> >>> <input type = "submit" value = "Update Movies" >>> id="formsubmit"/> >>> </form> >>> >>> The span is reproduced for each object that I pull from a database. >>> There is a different identifier for each span, as you can see here: >>> http://screencast.com/t/l8pLGZnJVn8 >>> >>> I want to be able to access these objects when I click submit the >>> form, but I'm not sure how to get access to them. This is what I have >>> tried so far: >>> >>> >>> Form moviesForm = new Form<ValueMap>("moviesForm") { >>> /** >>> * Show the resulting valid new movie >>> */ >>> @Override >>> public final void onSubmit() { >>> ValueMap values = getModelObject(); >>> >>> // perform validation and security here >>> if (StringUtils.isBlank((String) values.get("name"))) { >>> error("Received bad input!!!"); >>> return; >>> } >>> >>> Session session = >>> HibernateUtil.getSessionFactory().getCurrentSession(); >>> session.beginTransaction(); >>> >>> Movie movie = new Movie(); >>> movie.setName((String) values.get("name")); >>> movie.setCategory((Category) values.get("category")); >>> session.save(movie); >>> session.getTransaction().commit(); >>> } >>> >>> }; >>> >>> The ValueMap values comes back null from getModelObject(). Any >>> pointers for me to get these objects back in a way that I can easily >>> update them? >>> >>> Thanks. >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
