hmm

this wont really work, you see the list has to be loaded before onsubmit
because it is used to decode select component's value back to the object(
notice how we do not provide a reverse lookup in the renderer that does
id->value, only value->id)

if you really want to avoid the second load what you have to do is to use a
custom model that gives you access to the backing list so you can modify it
accordingly in onsubmit. ( i guess the ldm will work as well )

if you do not mind the second load then just detach the model in onsubmit

if you do not mind loads period because your persistence layer is doing
caching just do the query in model's getobject() so its fresh every time its
called.

also make sure whatever your locator returns is something you do not mind
being serialized.

-igor

On 2/5/07, Aaron HIniker <[EMAIL PROTECTED]> wrote:

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

-------------------------------------------------------------------------
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