On Sat, 04 Oct 2008, walnutmon wrote:
> I can manually assign the variable at run time using the getModelObject()
> function... I know you can bind through property models, is trying to do so
> with a regular Model() object wrong?

Do you mean this?

> > return new DropDownChoice("companies", new Model(company), 
> >                getCompanies, new ChoiceRenderer("name"));

What happens here is that the company object does not get
bound to the model dynamically, but only gets the initial
value from there. Look at the source code of Model -- 
setObject just stores the value internally.

If you want to make the DropDownChoice automatically
update the company value, you can do something like this

  return new DropDownChoicde("companies", new Model() {
      @Override
      public void setObject(Object chosenCompany) {
          company = (Company) chosenCompany;
      }

      @Override 
      public Object getObject() {
          return company;
      }
  }, getCompanies(), new ChoiceRenderer("name"));

This is essentially same as using the PropertyModel, only
more explicit and verbose and IDE friendly.

And read the page on models from the wiki, if you didn't
yet.

Note also that often it's better to abstract the access to
domain objects to go via IModel instead of holding direct
references to them, so your "company" field could actually
be an IModel<Company> that you can then use for the
DropDownChoice model directly.

Best wishes,
Timo


-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

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

Reply via email to