On Friday 09 November 2007 11:22:20 Toscano wrote: > Hello, > > I found some questions related to this topic, but I couldn't make it to > work. > I have two dropdowns, countries and regions. The easy thing is that I load > the regions when the country has been selected, and I use > AjaxFormComponentUpdatingBehavior for this and works. > The thing is that we don't have Regions for all the countries, so in that > cases I want to disable the dropdown. > > This is the code I have: > > > // countryWork is the first dropdown > countryWork.add(new AjaxFormComponentUpdatingBehavior("onchange") > { > protected void onUpdate(AjaxRequestTarget target) > { target.addComponent(regionWork); } > }); > > // and regionWork is the region > > IModel regionModelChoices = new AbstractReadOnlyModel() > { > public Object getObject(Component component) > { > if (professionalInfo.getCountryWork()!=null) > regions = > getRegionDaoInterface().getRegions(professionalInfo.getCountryWork().getCou >ntryID()); if (regions.size()==0) > regionWork.setEnabled(false); > else > regionWork.setEnabled(true); > return regions; > } > }; > > regionWork = new DropDownChoice("regionWork", new Model(), > regionModelChoices, > new ChoiceRenderer("regionName", "regionID")); > regionWork.setOutputMarkupId(true); > > The dropdown changes, but with one refresh delay. For example, I have > regions for Canada but not for Spain. If I change to Canada, nothing > happens, but the next change in the country will enable the dropdown. > > Any ideas? > > Thank you very much for your time, > Oskar
Probably that is because this component is already rendered. In general you shouldn't change components state inside a model because this code is called at render stage. In your case you can call regionWork.setEnabled() inside onUpdate(AjaxRequestTarget target). Dima --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]