Let me use the real situation:

Client 1--* Account 1--* Context 1--* Schedule

Here is the code simplified as much I can. If you think I have to add
something else just tell me:

public class AssignationPanel extends Panel {

 @SpringBean
private WSServicesIF services;
 private IModel<List<String>> assignationRolsModel = new
AssignationRolsModel();

public AssignationPanel(String id, IModel<AssignationBean> model) {
 super(id, model);

 final Form<Void> form = new Form<Void>("form");

final PropertyModel<Client> selectedClient = new
PropertyModel<Client>(model, "client");
 final PropertyModel<Account> selectedAccount = new
PropertyModel<Account>(model, "account");
 final PropertyModel<ContentType> selectedContext = new
PropertyModel<ContentType>(model, "context");

final Component clientSelector = new DropDownChoice<Client>("clients",
selectedClient, new ClientsModel(services), new
ClientRenderer()).setNullValid(false);
 final Component accountSelector = new DropDownChoice<Account>("accounts",
selectedAccount, new AccountsOfClientModel(selectedClient, services), new
AccountRenderer()).setNullValid(false).setOutputMarkupId(true);
 final Component contextSelector = new
DropDownChoice<ContentType>("contexts", selectedContext, new
ContextsOfAccountModel(selectedAccount, services), new
ContextRenderer()).setNullValid(false).setOutputMarkupId(true);
 final Component scheduleSelector = new
DropDownChoice<Schedule>("schedule", new PropertyModel<Schedule>(model,
"schedule"), new SchedulesOfContextModel(selectedContext, services), new
ScheduleRenderer()).setNullValid(false).setOutputMarkupId(true);
 clientSelector.add(new AjaxFormComponentUpdatingBehavior("onChange") {

@Override
 protected void onUpdate(AjaxRequestTarget target) {
target.addComponent(accountSelector);
 target.addComponent(contextSelector);
target.addComponent(scheduleSelector);
 }
});
 accountSelector.add(new AjaxFormComponentUpdatingBehavior("onChange") {

@Override
 protected void onUpdate(AjaxRequestTarget target) {
target.addComponent(contextSelector);
 target.addComponent(scheduleSelector);
}
 });
contextSelector.add(new AjaxFormComponentUpdatingBehavior("onChange") {

@Override
 protected void onUpdate(AjaxRequestTarget target) {
target.addComponent(scheduleSelector);
 }
});

form.add(clientSelector);
 form.add(accountSelector);
form.add(contextSelector);
 form.add(scheduleSelector, new
SimpleMessageComponentFeedbackPanel("scheduleError", scheduleSelector));

add(form);
 }
}

public class ClientsModel extends LoadableDetachableModel<List<Client>> {

private WSServicesIF services;

public ClientsModel(WSServicesIF services) {
 this.services = services;
}

@Override
 protected List<Client> load() {
return new ArrayList<Client>(services.getClients());
 }
}

public class AccountsOfClientModel extends
LoadableDetachableModel<List<Account>> {

 private WSServicesIF services;
private IModel<Client> client;

 public AccountsOfClientModel(IModel<Client> client, WSServicesIF services)
{
this.services = services;
 this.client = client;
}

@Override
 protected List<Account> load() {
Client object = client.getObject();
 if (object == null) {
return new ArrayList<Account>();
} else {
 return services.getSortedAccounts(object.getId().toString());
}
}
}

public class ContextsOfAccountModel extends
LoadableDetachableModel<List<ContentType>> {

private WSServicesIF services;
 private IModel<Account> account;

public ContextsOfAccountModel(IModel<Account> account, WSServicesIF
services) {
 this.account = account;
this.services = services;
}

@Override
protected List<ContentType> load() {
Account object = account.getObject();
 if (object == null || object.getId() == null) {
return new ArrayList<ContentType>();
 } else {
return services.getContentTypeForAccount(object.getId().toString());
 }
}
}

public class SchedulesOfContextModel extends
LoadableDetachableModel<List<Schedule>> {

private WSServicesIF services;
private IModel<ContentType> context;

public SchedulesOfContextModel(IModel<ContentType> context, WSServicesIF
services) {
this.context = context;
 this.services = services;
}

@Override
 protected List<Schedule> load() {
ContentType object = context.getObject();
 if (object == null) {
return new ArrayList<Schedule>();
} else {
 return new
ArrayList<Schedule>(services.getSchedulesForContext(object.getId().toString()));
}
 }
}



First is the code of a panel with dropdowns and then I pasted models of
choices to show the way I provide options. I can't see the problem, and in
a way is working, but fails following steps I mentioned in my previous mail.

Thanks for helping!


Norberto

2011/11/19 Jeremy Thomerson <[email protected]>

> show the code
>
> On Fri, Nov 18, 2011 at 1:36 PM, Tito <[email protected]> wrote:
>
> > Hi, I'm trying to connect three drowpdowns.
> >
> > For example.
> >
> > combo1: Country
> > combo2: Province
> > combo3: City
> >
> > I'm updating dropdowns by Ajax with
> > AjaxFormComponentUpdatingBehavior("onChange") and it works ok.
> > But if you choose a Country, then a Province, then a City and after that
> > you change the Country, the Province changes but not the city.
> >
> > I'm doing everything with models and adding all dropdowns to
> > AjaxRequestTarget.
> >
> > Regards
> >
> > Norberto
> >
>
>
>
> --
> Jeremy Thomerson
> http://wickettraining.com
> *Need a CMS for Wicket?  Use Brix! http://brixcms.org*
>

Reply via email to