form processing for multiple objects

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

form processing for multiple objects

Daniel Watrous-2
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: form processing for multiple objects

Daniel Watrous-2
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
<[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: form processing for multiple objects

Sven Meier
In reply to this post by Daniel Watrous-2
You should let Wicket set the entered values directly into your Movie
objects:

add(new PropertyListView("movies", moviesModel) {
   protected abstract void populateItem(ListItem item) {
     item.add(new TextField("name"));
     item.add(new DropDownChoice("category", categoriesModel));

     ...
   }
};

In #onSubmit() you'll just have to save the movies in the db.

Sven

Am 23.01.2012 17:07, schrieb Daniel Watrous:

> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: form processing for multiple objects

Sven Meier
In reply to this post by Daniel Watrous-2
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
> <[hidden email]>  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: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: form processing for multiple objects

Daniel Watrous-2
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 <[hidden email]> 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
>> <[hidden email]>  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: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: form processing for multiple objects

Sven Meier
Do you have the ValueMap usage from a Wicket example (e.g. Guestbook)?
You don't seem to have any code that wires a ValueMap into your form.

The following should be enough:

            @Override
            public final void onSubmit() {

                Session session = HibernateUtil.getSessionFactory().getCurrentSession();
                session.beginTransaction();

                for (Movie movie : listView.getModelObject()) {
                    session.save(movie);
                }
                session.getTransaction().commit();
            }

Hope this helps
Sven


Am 23.01.2012 17:27, schrieb Daniel Watrous:

> 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<[hidden email]>  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
>>> <[hidden email]>    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: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: form processing for multiple objects

Daniel Watrous-2
In reply to this post by Daniel Watrous-2
Note that I can access the objects that I populate using a
PropertyListView individually just fine.

What I am trying to do now is access them as part of a larger form so
that I can update multiple items at once. I was hoping to be able to
iterate through the items that the PropertyListView had rendered so
that I can update them one by one. That's where I'm failing. That Form
and onSubmit are defined outside of the PropertyListView.

I'm sorry if I'm not explaining this very well.

Daniel

On Mon, Jan 23, 2012 at 9:27 AM, Daniel Watrous
<[hidden email]> wrote:

> 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 <[hidden email]> 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
>>> <[hidden email]>  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: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: form processing for multiple objects

Daniel Watrous-2
In reply to this post by Sven Meier
Here's a little more code. You can see that I add the PropertyListView
to moviesForm...My listView (movieList) is a LoadableDetachableModel,
so it doesn't have the getModelObject() method. I'm still not quite
sure how to get access to the form details in onSubmit().

        Form moviesForm = new Form<ValueMap>("moviesForm") {
            /**
             * Show the resulting valid new movie
             */
            @Override
            public final void onSubmit() {
                Session session =
HibernateUtil.getSessionFactory().getCurrentSession();
                session.beginTransaction();

                for (Movie movie : movieList.getModelObject()) {
                    session.save(movie);
                }
                session.getTransaction().commit();
            }

        };

        // 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() {
                        Session session =
HibernateUtil.getSessionFactory().getCurrentSession();
                        session.beginTransaction();
                        session.delete(movieItem.getModelObject());
                        session.getTransaction().commit();

                        movieList.detach();
                    }
                });
            }
        }).setVersioned(false);

        add(moviesForm);





On Mon, Jan 23, 2012 at 9:33 AM, Sven Meier <[hidden email]> wrote:

> Do you have the ValueMap usage from a Wicket example (e.g. Guestbook)?
> You don't seem to have any code that wires a ValueMap into your form.
>
> The following should be enough:
>
>
>           @Override
>           public final void onSubmit() {
>
>               Session session =
> HibernateUtil.getSessionFactory().getCurrentSession();
>               session.beginTransaction();
>
>               for (Movie movie : listView.getModelObject()) {
>                   session.save(movie);
>               }
>               session.getTransaction().commit();
>           }
>
> Hope this helps
> Sven
>
>
> Am 23.01.2012 17:27, schrieb Daniel Watrous:
>
>> 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<[hidden email]>  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
>>>> <[hidden email]>    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: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: form processing for multiple objects

Sven Meier
How about this:

   http://paste.pocoo.org/show/539346/

Sven

Am 23.01.2012 17:53, schrieb Daniel Watrous:

> Here's a little more code. You can see that I add the PropertyListView
> to moviesForm...My listView (movieList) is a LoadableDetachableModel,
> so it doesn't have the getModelObject() method. I'm still not quite
> sure how to get access to the form details in onSubmit().
>
>          Form moviesForm = new Form<ValueMap>("moviesForm") {
>              /**
>               * Show the resulting valid new movie
>               */
>              @Override
>              public final void onSubmit() {
>                  Session session =
> HibernateUtil.getSessionFactory().getCurrentSession();
>                  session.beginTransaction();
>
>                  for (Movie movie : movieList.getModelObject()) {
>                      session.save(movie);
>                  }
>                  session.getTransaction().commit();
>              }
>
>          };
>
>          // 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() {
>                          Session session =
> HibernateUtil.getSessionFactory().getCurrentSession();
>                          session.beginTransaction();
>                          session.delete(movieItem.getModelObject());
>                          session.getTransaction().commit();
>
>                          movieList.detach();
>                      }
>                  });
>              }
>          }).setVersioned(false);
>
>          add(moviesForm);
>
>
>
>
>
> On Mon, Jan 23, 2012 at 9:33 AM, Sven Meier<[hidden email]>  wrote:
>> Do you have the ValueMap usage from a Wicket example (e.g. Guestbook)?
>> You don't seem to have any code that wires a ValueMap into your form.
>>
>> The following should be enough:
>>
>>
>>            @Override
>>            public final void onSubmit() {
>>
>>                Session session =
>> HibernateUtil.getSessionFactory().getCurrentSession();
>>                session.beginTransaction();
>>
>>                for (Movie movie : listView.getModelObject()) {
>>                    session.save(movie);
>>                }
>>                session.getTransaction().commit();
>>            }
>>
>> Hope this helps
>> Sven
>>
>>
>> Am 23.01.2012 17:27, schrieb Daniel Watrous:
>>
>>> 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<[hidden email]>    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
>>>>> <[hidden email]>      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: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: form processing for multiple objects

Daniel Watrous-2
I ended up with something similar (see also this post:
http://apache-wicket.1842946.n4.nabble.com/Add-new-items-to-a-list-within-a-form-by-ajaxlink-td2017446.html)

http://paste.pocoo.org/show/539351/

I created a class level variable that would hold my PropertyListView
which made it available to the my onSubmit() method in the form.

Thank you so much for your help.

Daniel

On Mon, Jan 23, 2012 at 10:20 AM, Sven Meier <[hidden email]> wrote:

> How about this:
>
>  http://paste.pocoo.org/show/539346/
>
> Sven
>
> Am 23.01.2012 17:53, schrieb Daniel Watrous:
>
>> Here's a little more code. You can see that I add the PropertyListView
>> to moviesForm...My listView (movieList) is a LoadableDetachableModel,
>> so it doesn't have the getModelObject() method. I'm still not quite
>> sure how to get access to the form details in onSubmit().
>>
>>         Form moviesForm = new Form<ValueMap>("moviesForm") {
>>             /**
>>              * Show the resulting valid new movie
>>              */
>>             @Override
>>             public final void onSubmit() {
>>                 Session session =
>> HibernateUtil.getSessionFactory().getCurrentSession();
>>                 session.beginTransaction();
>>
>>                 for (Movie movie : movieList.getModelObject()) {
>>                     session.save(movie);
>>                 }
>>                 session.getTransaction().commit();
>>             }
>>
>>         };
>>
>>         // 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() {
>>                         Session session =
>> HibernateUtil.getSessionFactory().getCurrentSession();
>>                         session.beginTransaction();
>>                         session.delete(movieItem.getModelObject());
>>                         session.getTransaction().commit();
>>
>>                         movieList.detach();
>>                     }
>>                 });
>>             }
>>         }).setVersioned(false);
>>
>>         add(moviesForm);
>>
>>
>>
>>
>>
>> On Mon, Jan 23, 2012 at 9:33 AM, Sven Meier<[hidden email]>  wrote:
>>>
>>> Do you have the ValueMap usage from a Wicket example (e.g. Guestbook)?
>>> You don't seem to have any code that wires a ValueMap into your form.
>>>
>>> The following should be enough:
>>>
>>>
>>>           @Override
>>>           public final void onSubmit() {
>>>
>>>               Session session =
>>> HibernateUtil.getSessionFactory().getCurrentSession();
>>>               session.beginTransaction();
>>>
>>>               for (Movie movie : listView.getModelObject()) {
>>>                   session.save(movie);
>>>               }
>>>               session.getTransaction().commit();
>>>           }
>>>
>>> Hope this helps
>>> Sven
>>>
>>>
>>> Am 23.01.2012 17:27, schrieb Daniel Watrous:
>>>
>>>> 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<[hidden email]>    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
>>>>>> <[hidden email]>      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: [hidden email]
>>>>>> For additional commands, e-mail: [hidden email]
>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]