我正在尝试访问用户在 apache wicket 的 DropDownChoices 中选择的值。我将 AjaxFormComponentUpdatingBehavior 添加到 DropDownChoices 元素。我在 onUpdate 行为方法中将 null 作为选定选项。我尝试通过不同的方式访问选定的值,如下面的代码所示,但在调试时仍然为空。
私有字符串 selectedMake;
private final Map<String, List<String>> modelsMap = new HashMap<String, List<String>>(); // map:company->model
modelsMap.put( "AUDI", Arrays.asList( "A4", "A6", "TT" ) );
modelsMap.put( "CADILLAC", Arrays.asList( "CTS", "DTS", "ESCALADE", "SRX", "DEVILLE" ) );
modelsMap.put( "FORD", Arrays.asList( "CROWN", "ESCAPE", "EXPEDITION", "EXPLORER", "F-150" ) );
IModel<List<? extends String>> makeChoices = new AbstractReadOnlyModel<List<? extends String>>() {
@Override
public List<String> getObject() {
return new ArrayList<String>( modelsMap.keySet() );
}
};
lastDropDownChoice = new DropDownChoice<String>( "daynamicTimeConstrains",
new PropertyModel<String>( this, "selectedMake" ), makeChoices );
lastDropDownChoice.add( new AjaxFormComponentUpdatingBehavior( "onchange" ) {
@Override
protected void onUpdate( AjaxRequestTarget target ) {
// Getting this as null
System.out.println( selectedMake );
// Getting this as null
getFormComponent().getModel().getObject();
}
} );