Well, I found some detachable model documentation and figured it out.
LDM::detach() will cause a getObject() call to load().  Putting detach early
in my Form::submit() was sufficient for this example.

Another wrinkle was that I also had a Button with the same issue and putting
detach() in Button::onSubmit() was not work.  Changing the Button to a Link
and using onClick() did, though.

-troy

On Thu, Jul 30, 2009 at 7:29 PM, Troy Cauble <troycau...@gmail.com> wrote:

> Here's a minimal example of my problem.
> Again, the LDM::getObject() call AFTER the onSubmit()
> call that changes the data does not result in a LDM::load().
>
> There's a load() before the onSubmit(), but that's too early.
>
> Anyone?  What am I missing?
>
> Thanks,
> -troy
>
>
>     [jetty] DDC choices LDM: getObject
>     [jetty] DDC choices LDM: load(reading choices)
>     [jetty] DDC choices LDM: onAttach
>     [jetty] Form onSubmit
>     [jetty] DDC choices LDM: getObject
>     [jetty] DDC choices LDM: onDetach
>     [jetty]
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <html>
>   <head></head>
>   <body>
>   Pressing the button adds an entry to the drop down list,
>   but you can't see it without reloading the page.
>   <br/>
>   What am I missing?
>       <div style="position:relative; left:10px;">
>         <br/>
>         <form wicket:id="form" style="position:relative; left:10px;">
>           <select wicket:id="ddc"/>
>         <input type="submit" value="add an entry"/>
>         </form>
>       </div>
>   </body>
> </html>
>
> package dummy;
>
> import java.util.*;
>
> import org.apache.wicket.PageParameters;
> import org.apache.wicket.markup.html.WebPage;
> import org.apache.wicket.markup.html.form.*;
> import org.apache.wicket.model.*;
>
> public class Dummy extends WebPage
> {
>     private static final long serialVersionUID = 1L;
>
>     private ArrayList<String>    choices = new ArrayList<String>();
>     private Integer            item = new Integer(1);
>
>     public Dummy(final PageParameters parameters)
>     {
>         super(parameters);
>
>         choices.add(item.toString());
>
>         IModel choicesModel = new LoadableDetachableModel() {
>             private static final long serialVersionUID = 1L;
>             @Override
>             protected void onAttach() {
>                 System.out.println("DDC choices LDM: onAttach");
>                 super.onAttach();
>             }
>             @Override
>             protected void onDetach() {
>                 System.out.println("DDC choices LDM: onDetach\n");
>                 super.onDetach();
>             }
>             @Override
>             public Object getObject() {
>                 System.out.println("DDC choices LDM: getObject");
>                 return super.getObject();
>             }
>             @Override
>             protected Object load() {
>                 System.out.println("DDC choices LDM: load(reading
> choices)");
>                 // Note the clone() --
>                 // to simulate a hibernate pull
>                 return choices.clone();
>             }
>         };
>
>         final DropDownChoice ddc = new DropDownChoice("ddc",
>                         new Model(), choicesModel);
>
>         Form form = new Form("form") {
>
>             private static final long serialVersionUID = 1L;
>
>             @Override
>             protected void onSubmit()
>             {
>                 System.err.printf("Form onSubmit\n");
>                 ddc.setModelObject(null);
>                 choices.add((++item).toString());
>             }
>         };
>
>         add(form);
>         form.add(ddc);
>     }
> }
>
>

Reply via email to