我正在创建List
:SelectItem
List<SelectItem> activityGlobalTypes = new ArrayList<SelectItem>();
for (ActivityTypeXMLModel activityTypeXMLModel : filteredActivityTypeXMLModels) {
activityGlobalTypes.add(new SelectItem(activityTypeXMLModel, activityTypeXMLModel.getParent()));
}
这是下拉菜单:
<p:selectOneMenu id="activityGlobalMenu" value="#{adminController.activityDTO.activityParentName}" required="true">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{adminController.activityGlobalTypes}" />
<p:ajax listener="#{adminController.updateDependentActivity}" />
</p:selectOneMenu>
现在从方法updateDependentActivity
public void updateDependentActivity(AjaxBehaviorEvent event) {
SelectOneMenu menu = (SelectOneMenu) event.getComponent();
System.out.println(menu.getValue());//it prints com.edfx.adb.xml.model.ActivityTypeXMLModel@7b6fe3c4
if(menu.getValue() instanceof ActivityTypeXMLModel) {
System.out.println("value is ActivityTypeXMLModel"); // I was expecting this one
} else if(menu.getValue() instanceof String) {
System.out.println("value is String"); //this line is executing
} else {
System.out.println("unknown");
}
}
我检查了源代码,SelectItem
它以对象形式存储值。任何指针都会非常有帮助。