有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java更改wicket中第二个下拉列表的模型值

我在wicket中有两个下拉列表,从第一个下拉列表中选择任意值,然后相应地更改第二个下拉列表。现在,如果我从第二个下拉列表中选择任何值,那么数据应该改变,这很好

现在再次说明,如果我从第一个下拉列表中选择了默认值/“所有”值,那么第二个下拉列表的第二个默认值应该是“所有”,而不是在下拉列表中显示所选值

下面是我的代码:

/*
countryList having -- All, India, Srilanka, US, UK
for All --> All, U.P., Delhi, colombo, England, New York, Washington
stateList for India --> All, U.P., Delhi
For Srilanka--> All,colombo, For US --> All, New York, Washington, For UK --> All, England
*/

DropDownChoice<Country> country = new DropDownChoice<Country>("country",
        new PropertyModel<Country>(params, "selectedCountry"),
        countryList, new ChoiceRenderer<Country>("countryName", "countryId"));
DropDownChoice<State> state = new DropDownChoice<State>("state",
        new PropertyModel<State>(params, "selectedState"),
        stateList, new ChoiceRenderer<State>("stateName", "stateId"));

country.add(new AjaxFormComponentUpdatingIndicatingBehavior("onchange") {
    @Override
    protected void onUpdate(AjaxRequestTarget target) {
        if (/* provide some condition*/) {
            params.setSelectedState("ALL");
        }
        target.add(state);
    }
});

但它并没有在第二个下拉列表中显示selectedstate的所有内容


共 (1) 个答案

  1. # 1 楼答案

    问题确实出在==的用法上,您可以在其中检查所选的国家/地区。目前还不清楚params的类型是什么,但从new PropertyModel<Country>(params, "selectedCountry")来看,它似乎是一个具有Country类型的属性selectedCountry,其中Country具有countryNamecountryId。所以if (params.getSelectedCountry() == "ALL")不是没有编译就是做错了什么