Hi Walter,
you should keep the type of the DDC's model object the same as the type
of choices.
Either use full blown objects:
IModel<My> myModel = new MyLDM(...);
add(new DropDownChoice<My>( "idSelection", myModel, new
PropertyModel<My>(Cases, "allCases")) {
@Override
protected void onSelectionChanged(My newSelection) {
// nothing to do for the selection since the selected
choice is already pushed into myModel.
}
});
Or if it is to expensive to load all objects go for Strings only:
MyLDM myModel = new MyLDM(...);
IModel<String> stringModel = new IModel() {
public void setObject(String value) {
myModel.setId(value);
}
public String getObject() {
return myModel.getId();
}
};
add(new DropDownChoice<String>( "idSelection", stringModel, new
PropertyModel<String>(Cases, "allCases")) {
@Override
protected void onSelectionChanged(Object newSelection) {
// nothing to do for the selection since the selected
choice is already pushed into myModel.
}
});
See how myModel adapts MyLDM to Strings.
BTW changing model references is a recipe for disaster in most cases:
myLDM = new MyLDM((String) newSelection);
You never know who holds a reference to the old model and thus misses the
update (as the DropDownChoice in your code).
Hope this helps
Sven
On 06/21/2012 10:11 AM, Walter Rugora wrote:
Hi there,
I've a LoadableDetachableModel which works pretty much like all LDM
examples. There is an overwritten load method that returns an object
based on an id member which is set via the constructor.
In addition there is a DropDownChoice added to the WebPage (no form is
used). The choices object is a model which returns a list of Strings.
Each string of that list represents an id which is necessary to retrieve
an object.
And here the problem start. I'd like to use the LDM to return an object
based on the selected id of the DDC.
Beside the component id and the choices list (IModel), I'd like to
utilize the third mode parameter (IModel). From my understanding, model
allows to preselect an item in the DCC. But as well the item selected by
the user is that written back into Model. Very convenient!
But in my case, since choices is based on a list of Strings, only a
String is written to the model.
So, I don't know how to connect the new value of my DDC model with the
LDM that I use.
As well, I overwrite the onSelectionChanged method of the DDC. Within
this method I try to assign a new LDM with the newSelection value as a
constructor argument to a global LDM model, but the LDM id member value
never changes:
public class HomePage extends WebPage{
private MyLDM myLDM = new MyLDM("123");
...
public HomePage(final PageParameters parameters) {
...
add(new DropDownChoice(
"idSelection",
[a model ... but how to use it to update the LDM id],
new PropertyModel(Cases, "allCases")) {
@Override
protected void onSelectionChanged(Object newSelection) {
myLDM= new MyLDM((String) newSelection);
}
...
I'm very much lost. Maybe my approach is simply wrong. I have the gut
feeling that it is easy to solve, but as a beginner I got lost in the
model jungle. Get me out there ... please ;)
Thanks,
Walter
---------------------------------------------------------------------
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]