Oh ok.  I didn't think about solving the problem with that approach.  Thanks

-----Original Message-----
From: Johan Compagner [mailto:[EMAIL PROTECTED] 
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 <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to