This is just a question as to a "best approach" to take to ensure that a
form component's model is updated after onSubmit() does it's work.

Given the code:


public class MyForm extends Form< Foo >
{
    private static final Log log = LogFactory.getLog(MyForm.class);

    IEntityServices server =
ServiceLocator.getDefault().locateAndCreate(EntityServices.class);

    public MyForm(MarkupContainer markupContainer, String s, IModel< Foo
> iModel)
    {
        super(markupContainer, s, new CompoundPropertyModel(iModel));

        new TextField(this, "name");
        new DropDownChoice< Foo >(
                this,
                "parent",
                new LoadableDetachableModel< List< Foo > >() {
                    protected List< Foo > load() {
                        log.debug("Calling Load....");
                        return server.getResultList("SELECT f FROM Foo
f");  //<-- called 1st, N entities in the table
                    }
                },
                new ChoiceRenderer< Foo >("name", "id")
        );
    }

    protected void onSubmit()
    {
        server.merge(getModelObject());  //<-- called 2nd, saves new
entity, now N+1 entities in the table
    }
}


Sorry, I know sifting through others code isn't much fun, but I included
it just to be clear.  I know the javadoc says that a Form will update
all of it's FormComponent models before calling onSubmit().  In this
case, I am loading the entire list of "Foo"'s from the database for the
DropDownChoice that the user can select to be this new Foo's parent.  
Because the DropDownChoice loads it's model before onSubmit(), it will
never include the newly created Foo that is saved in onSubmit().  Only
after a subsequent page refresh/render will the saved Foo get loaded.

Basically, my question is:  what is a clean way to ensure that the
DropDownModel gets loaded only once still (via the
LoadableDetachableModel), but *after* the onSubmit() is called?

Aaron

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to