LoadableDetachableModel for drop-down menu selection

2008-10-28 Thread Gianni Doe
I'm starting out with Wicket and following the Wicket In Action  
examples through and I'm a bit stuck on how to make use of a  
LoadableDetachableModel in a drop-down menu situation.


I've got a drop-down menu of countries which is populated from a  
LoadableDetachableModel, this works perfectly but my selected Country  
is then stored in the page as a complete object, I'd like to be able  
to make use of LoadableDetachableModel also for the selectedCountry  
but I'm not clear on where and how I should instantiate it.
i.e. for the example below where do I put the new  
LoadableRefDataModelCountry(selectedCountry);.


I'd appreciate some suggestions, I think I'm getting the hang of the  
Model idea but can't see the wood for the trees at the moment.




public class LocationSearchPage extends WebPage {

private DropDownChoiceCountry countryChoice;

private DropDownChoiceLocation locationChoice;

private Country selectedCountry;

private ListLocation locations = new ArrayListLocation();

private Location selectedLocation;

@SpringBean
private RefDataService refDataService;

public LocationSearchPage() {

Form searchForm = new Form(searchForm) {
@Override
protected void onSubmit() {
//...
}
};
add(searchForm);

ChoiceRenderer countryRenderer = new  
ChoiceRenderer(description, id);
IModelList? extends Country countryModel = new  
LoadableDetachableModelList? extends Country() {

@Override
protected ListCountry load() {
return refDataService.getCountries();
}
};

countryChoice = new DropDownChoiceCountry(
country, selectedCountry, countryModel,  
countryRenderer);


countryChoice.add(new  
AjaxFormComponentUpdatingBehavior(onchange) {

protected void onUpdate(AjaxRequestTarget target) {
this.selectedLocation = null;
locationChoice.setChoices(new  
ArrayListCountry(selectedCountry.getLocations()));

target.addComponent(locationChoice);
}
});

ChoiceRenderer locationRenderer = new  
ChoiceRenderer(description, id);

locationChoice = new DropDownChoiceLocation(
location, new PropertyModelLocation(this,  
selectedLocation), locations, locationRenderer);

}
}


public class LoadableRefDataModelT extends RefData extends  
LoadableDetachableModel {


@SpringBean
private RefDataService refDataService;

private ClassT type;

private Serializable id;

public LoadableRefDataModel(ClassT type, Serializable id) {
InjectorHolder.getInjector().inject(this);
this.type = type;
this.id = id;
}

public LoadableRefDataModel(T domainObject) {
super(domainObject);
InjectorHolder.getInjector().inject(this);
this.type = (ClassT) domainObject.getClass();
this.id = domainObject.getCode();
}

@Override
protected T load() {
return refDataService.load(type, id);
}
}


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



Re: LoadableDetachableModel for drop-down menu selection

2008-10-28 Thread Igor Vaynberg
this should give you an idea

http://wicketinaction.com/2008/09/building-a-smart-entitymodel/

-igor

On Tue, Oct 28, 2008 at 12:27 PM, Gianni Doe [EMAIL PROTECTED] wrote:
 I'm starting out with Wicket and following the Wicket In Action examples
 through and I'm a bit stuck on how to make use of a LoadableDetachableModel
 in a drop-down menu situation.

 I've got a drop-down menu of countries which is populated from a
 LoadableDetachableModel, this works perfectly but my selected Country is
 then stored in the page as a complete object, I'd like to be able to make
 use of LoadableDetachableModel also for the selectedCountry but I'm not
 clear on where and how I should instantiate it.
 i.e. for the example below where do I put the new
 LoadableRefDataModelCountry(selectedCountry);.

 I'd appreciate some suggestions, I think I'm getting the hang of the Model
 idea but can't see the wood for the trees at the moment.



 public class LocationSearchPage extends WebPage {

private DropDownChoiceCountry countryChoice;

private DropDownChoiceLocation locationChoice;

private Country selectedCountry;

private ListLocation locations = new ArrayListLocation();

private Location selectedLocation;

@SpringBean
private RefDataService refDataService;

public LocationSearchPage() {

Form searchForm = new Form(searchForm) {
@Override
protected void onSubmit() {
//...
}
};
add(searchForm);

ChoiceRenderer countryRenderer = new ChoiceRenderer(description,
 id);
IModelList? extends Country countryModel = new
 LoadableDetachableModelList? extends Country() {
@Override
protected ListCountry load() {
return refDataService.getCountries();
}
};

countryChoice = new DropDownChoiceCountry(
country, selectedCountry, countryModel, countryRenderer);

countryChoice.add(new AjaxFormComponentUpdatingBehavior(onchange) {
protected void onUpdate(AjaxRequestTarget target) {
this.selectedLocation = null;
locationChoice.setChoices(new
 ArrayListCountry(selectedCountry.getLocations()));
target.addComponent(locationChoice);
}
});

ChoiceRenderer locationRenderer = new ChoiceRenderer(description,
 id);
locationChoice = new DropDownChoiceLocation(
location, new PropertyModelLocation(this,
 selectedLocation), locations, locationRenderer);
}
 }


 public class LoadableRefDataModelT extends RefData extends
 LoadableDetachableModel {

@SpringBean
private RefDataService refDataService;

private ClassT type;

private Serializable id;

public LoadableRefDataModel(ClassT type, Serializable id) {
InjectorHolder.getInjector().inject(this);
this.type = type;
this.id = id;
}

public LoadableRefDataModel(T domainObject) {
super(domainObject);
InjectorHolder.getInjector().inject(this);
this.type = (ClassT) domainObject.getClass();
this.id = domainObject.getCode();
}

@Override
protected T load() {
return refDataService.load(type, id);
}
 }


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



Re: LoadableDetachableModel for drop-down menu selection

2008-10-28 Thread Gianni
Thanks Igor, I've already got my entity model LoadableRefDataModel  
which is similar to your example and I can see how to make use of this  
when I've actually got the entity object or id. My problem is I'm not  
clear on how I go about creating the entity model when a value is  
selected from my drop-down menu.



  private Country selectedCountry;



countryChoice = new DropDownChoiceCountry(
  country, selectedCountry, countryModel,  
countryRenderer);



In the above example selectedCountry is populated when a value is  
selected from the drop-down, what I'd like to do is replace  
selectedCountry with a LoadableDetachableModel.

i.e.
private LoadableRefDataModel Country country;

But I can't work out where to put the instantiation code. Is there  
some method of DropDownChoice I can override to do this or would I  
wrap my entity model in another model, overriding setObject() to  
instantiate my entity model.

What would be the recommended way?
-Gianni



On 28/ott/08, at 21:06, Igor Vaynberg wrote:


this should give you an idea

http://wicketinaction.com/2008/09/building-a-smart-entitymodel/

-igor

On Tue, Oct 28, 2008 at 12:27 PM, Gianni Doe [EMAIL PROTECTED]  
wrote:
I'm starting out with Wicket and following the Wicket In Action  
examples
through and I'm a bit stuck on how to make use of a  
LoadableDetachableModel

in a drop-down menu situation.

I've got a drop-down menu of countries which is populated from a
LoadableDetachableModel, this works perfectly but my selected  
Country is
then stored in the page as a complete object, I'd like to be able  
to make
use of LoadableDetachableModel also for the selectedCountry but I'm  
not

clear on where and how I should instantiate it.
i.e. for the example below where do I put the new
LoadableRefDataModelCountry(selectedCountry);.

I'd appreciate some suggestions, I think I'm getting the hang of  
the Model

idea but can't see the wood for the trees at the moment.



public class LocationSearchPage extends WebPage {

  private DropDownChoiceCountry countryChoice;

  private DropDownChoiceLocation locationChoice;

  private Country selectedCountry;

  private ListLocation locations = new ArrayListLocation();

  private Location selectedLocation;

  @SpringBean
  private RefDataService refDataService;

  public LocationSearchPage() {

  Form searchForm = new Form(searchForm) {
  @Override
  protected void onSubmit() {
  //...
  }
  };
  add(searchForm);

  ChoiceRenderer countryRenderer = new  
ChoiceRenderer(description,

id);
  IModelList? extends Country countryModel = new
LoadableDetachableModelList? extends Country() {
  @Override
  protected ListCountry load() {
  return refDataService.getCountries();
  }
  };

  countryChoice = new DropDownChoiceCountry(
  country, selectedCountry, countryModel,  
countryRenderer);


  countryChoice.add(new  
AjaxFormComponentUpdatingBehavior(onchange) {

  protected void onUpdate(AjaxRequestTarget target) {
  this.selectedLocation = null;
  locationChoice.setChoices(new
ArrayListCountry(selectedCountry.getLocations()));
  target.addComponent(locationChoice);
  }
  });

  ChoiceRenderer locationRenderer = new  
ChoiceRenderer(description,

id);
  locationChoice = new DropDownChoiceLocation(
  location, new PropertyModelLocation(this,
selectedLocation), locations, locationRenderer);
  }
}


public class LoadableRefDataModelT extends RefData extends
LoadableDetachableModel {

  @SpringBean
  private RefDataService refDataService;

  private ClassT type;

  private Serializable id;

  public LoadableRefDataModel(ClassT type, Serializable id) {
  InjectorHolder.getInjector().inject(this);
  this.type = type;
  this.id = id;
  }

  public LoadableRefDataModel(T domainObject) {
  super(domainObject);
  InjectorHolder.getInjector().inject(this);
  this.type = (ClassT) domainObject.getClass();
  this.id = domainObject.getCode();
  }

  @Override
  protected T load() {
  return refDataService.load(type, id);
  }
}


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





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