You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Dan Kaplan <dk...@citizenhawk.com> on 2007/12/16 10:41:05 UTC

ListChoice gets updated BEFORE onSubmit is called

Hello, I'm very new to wicket so this may be a "duh" situation, but here's
what I'm trying to do:

 

I have a form that shows you a ChoiceList of things.  You can select one and
then hit the submit button to delete that item.  I've written this
functionality but found that it doesn't work the way I want.  For some
reason, Wicket asks the ChoiceList for its list BEFORE the form's onSumbit
is called.  As a result, the page gets the list before the item is deleted.
And as a result of that, the item is still in the list even though it's been
removed from the database.  If I refresh my browser, the item disappears.
So, my question is, how do I get the ChoiceList to ask for its list AFTER
the form's onSubmit is called?  Here's my code (note that I'm extending
ChoiceList, but I don't think I'm overriding any related functionality):

 

//the choicelist

public class WorldChoiceList extends ListChoice {

 

    @SpringBean

    private WorldService worldService;

       

    public WorldChoiceList(String id, IModel model) {

        super(id);

        setChoices(new LoadableDetachableModel() {

            protected Object load() {

                return worldService.allByName();

            }

        });

        setChoiceRenderer(new IChoiceRenderer() {

            public Object getDisplayValue(Object object) {

                World w = ((World) object);

                return w.getName() + "," + w.getMaxX() + "," + w.getMaxY();

            }

 

            public String getIdValue(Object object, int index) {

                if (object.equals("")) {

                    return "";

                }

                return String.valueOf(((World) object).getWorldId());

            }

        });

        setModel(model);

        setNullValid(false);

    }

 

    /**

     * This override makes it so that the List does not start with a blank
or a "Choose One"

     * label.

     * @param selected The selected object

     * @return ""

     */

    protected CharSequence getDefaultChoice(final Object selected) {

        return "";

    }

}

 

//the web page

public class AdminHome extends AdminPage {

 

    @SpringBean

    private WorldService worldService;

 

    private World selected;

 

    public AdminHome() {

        add(new FeedbackPanel("feedback"));

        Form form = new Form("form") {

            public void onSubmit() {

                if (selected != null)

                    worldService.deleteWorld(selected);                

            }

        };

        form.add(new WorldChoiceList("worldList", new Model() {            

            public void setObject(final Object object) {

                selected = (World) object;

            }

        }));

        add(form);

 

        add(new BookmarkablePageLink("createWorld", CreateWorld.class));

    }

}

 

Thanks for any help :-)


RE: ListChoice gets updated BEFORE onSubmit is called

Posted by Dan Kaplan <dk...@citizenhawk.com>.
Oh ok.  I didn't think about solving the problem with that approach.  Thanks

-----Original Message-----
From: Johan Compagner [mailto:jcompagner@gmail.com] 
Sent: Sunday, December 16, 2007 2:10 AM
To: users@wicket.apache.org
Subject: Re: ListChoice gets updated BEFORE onSubmit is called

It has to get the list, because thats where the selected object comes
from. What you need to do is remove the object through that list or
call detach on the choice in the submit. That should also result in
the list being detached/cleared.

On 12/16/07, Dan Kaplan <dk...@citizenhawk.com> wrote:
> Hello, I'm very new to wicket so this may be a "duh" situation, but here's
> what I'm trying to do:
>
>
>
> I have a form that shows you a ChoiceList of things.  You can select one
and
> then hit the submit button to delete that item.  I've written this
> functionality but found that it doesn't work the way I want.  For some
> reason, Wicket asks the ChoiceList for its list BEFORE the form's onSumbit
> is called.  As a result, the page gets the list before the item is
deleted.
> And as a result of that, the item is still in the list even though it's
been
> removed from the database.  If I refresh my browser, the item disappears.
> So, my question is, how do I get the ChoiceList to ask for its list AFTER
> the form's onSubmit is called?  Here's my code (note that I'm extending
> ChoiceList, but I don't think I'm overriding any related functionality):
>
>
>
> //the choicelist
>
> public class WorldChoiceList extends ListChoice {
>
>
>
>     @SpringBean
>
>     private WorldService worldService;
>
>
>
>     public WorldChoiceList(String id, IModel model) {
>
>         super(id);
>
>         setChoices(new LoadableDetachableModel() {
>
>             protected Object load() {
>
>                 return worldService.allByName();
>
>             }
>
>         });
>
>         setChoiceRenderer(new IChoiceRenderer() {
>
>             public Object getDisplayValue(Object object) {
>
>                 World w = ((World) object);
>
>                 return w.getName() + "," + w.getMaxX() + "," +
w.getMaxY();
>
>             }
>
>
>
>             public String getIdValue(Object object, int index) {
>
>                 if (object.equals("")) {
>
>                     return "";
>
>                 }
>
>                 return String.valueOf(((World) object).getWorldId());
>
>             }
>
>         });
>
>         setModel(model);
>
>         setNullValid(false);
>
>     }
>
>
>
>     /**
>
>      * This override makes it so that the List does not start with a blank
> or a "Choose One"
>
>      * label.
>
>      * @param selected The selected object
>
>      * @return ""
>
>      */
>
>     protected CharSequence getDefaultChoice(final Object selected) {
>
>         return "";
>
>     }
>
> }
>
>
>
> //the web page
>
> public class AdminHome extends AdminPage {
>
>
>
>     @SpringBean
>
>     private WorldService worldService;
>
>
>
>     private World selected;
>
>
>
>     public AdminHome() {
>
>         add(new FeedbackPanel("feedback"));
>
>         Form form = new Form("form") {
>
>             public void onSubmit() {
>
>                 if (selected != null)
>
>                     worldService.deleteWorld(selected);
>
>             }
>
>         };
>
>         form.add(new WorldChoiceList("worldList", new Model() {
>
>             public void setObject(final Object object) {
>
>                 selected = (World) object;
>
>             }
>
>         }));
>
>         add(form);
>
>
>
>         add(new BookmarkablePageLink("createWorld", CreateWorld.class));
>
>     }
>
> }
>
>
>
> Thanks for any help :-)
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: ListChoice gets updated BEFORE onSubmit is called

Posted by Johan Compagner <jc...@gmail.com>.
It has to get the list, because thats where the selected object comes
from. What you need to do is remove the object through that list or
call detach on the choice in the submit. That should also result in
the list being detached/cleared.

On 12/16/07, Dan Kaplan <dk...@citizenhawk.com> wrote:
> Hello, I'm very new to wicket so this may be a "duh" situation, but here's
> what I'm trying to do:
>
>
>
> I have a form that shows you a ChoiceList of things.  You can select one and
> then hit the submit button to delete that item.  I've written this
> functionality but found that it doesn't work the way I want.  For some
> reason, Wicket asks the ChoiceList for its list BEFORE the form's onSumbit
> is called.  As a result, the page gets the list before the item is deleted.
> And as a result of that, the item is still in the list even though it's been
> removed from the database.  If I refresh my browser, the item disappears.
> So, my question is, how do I get the ChoiceList to ask for its list AFTER
> the form's onSubmit is called?  Here's my code (note that I'm extending
> ChoiceList, but I don't think I'm overriding any related functionality):
>
>
>
> //the choicelist
>
> public class WorldChoiceList extends ListChoice {
>
>
>
>     @SpringBean
>
>     private WorldService worldService;
>
>
>
>     public WorldChoiceList(String id, IModel model) {
>
>         super(id);
>
>         setChoices(new LoadableDetachableModel() {
>
>             protected Object load() {
>
>                 return worldService.allByName();
>
>             }
>
>         });
>
>         setChoiceRenderer(new IChoiceRenderer() {
>
>             public Object getDisplayValue(Object object) {
>
>                 World w = ((World) object);
>
>                 return w.getName() + "," + w.getMaxX() + "," + w.getMaxY();
>
>             }
>
>
>
>             public String getIdValue(Object object, int index) {
>
>                 if (object.equals("")) {
>
>                     return "";
>
>                 }
>
>                 return String.valueOf(((World) object).getWorldId());
>
>             }
>
>         });
>
>         setModel(model);
>
>         setNullValid(false);
>
>     }
>
>
>
>     /**
>
>      * This override makes it so that the List does not start with a blank
> or a "Choose One"
>
>      * label.
>
>      * @param selected The selected object
>
>      * @return ""
>
>      */
>
>     protected CharSequence getDefaultChoice(final Object selected) {
>
>         return "";
>
>     }
>
> }
>
>
>
> //the web page
>
> public class AdminHome extends AdminPage {
>
>
>
>     @SpringBean
>
>     private WorldService worldService;
>
>
>
>     private World selected;
>
>
>
>     public AdminHome() {
>
>         add(new FeedbackPanel("feedback"));
>
>         Form form = new Form("form") {
>
>             public void onSubmit() {
>
>                 if (selected != null)
>
>                     worldService.deleteWorld(selected);
>
>             }
>
>         };
>
>         form.add(new WorldChoiceList("worldList", new Model() {
>
>             public void setObject(final Object object) {
>
>                 selected = (World) object;
>
>             }
>
>         }));
>
>         add(form);
>
>
>
>         add(new BookmarkablePageLink("createWorld", CreateWorld.class));
>
>     }
>
> }
>
>
>
> Thanks for any help :-)
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org