如何将所选值设置为p:selectOneMenu?

时间:2015-07-02 05:43:01

标签: javascript primefaces

我有p:selectOneMenu

        <p:selectOneMenu styleClass="categoryList" filter="true"
                    id="parentCategoryList" style="width: 200px" effect="fade"
                    panelStyleClass="categoryListPanel"
                    converter="#{categoryConverter}" widgetVar="categoryListWV"
                    value="#{categoryService.category}">
                    <p:ajax event="change" update="@this" />
                    <f:selectItem itemLabel="No parent" />
                    <f:selectItems var="currCateg"
                        value="#{categoryService.categories}"
                        itemLabel="#{currCateg.name}" itemValue="#{currCateg}" />
                </p:selectOneMenu>   

我需要通过javascript设置值。在网络上我找到了这个解决方案:

widgetVar.selectValue(value);  

我将它应用于我的案例:

&#13;
&#13;
function addNewSubCategory() {
	var div = document.getElementsByClassName("ui-state-highlight")[0];
	var label = div.getElementsByTagName("label")[0];
	var parent = label.innerHTML;//name of item, String 
	if (parent === 'Shop')
		return;
	categoryListWV.selectValue(parent);//invoked, but does not set value
	alert(categoryListWV.getSelectedValue());//works correct
	alert(categoryListWV.getSelectedLabel());//works correct
	openAddCategBtn();//open dialog where p:selectOneMenu located
}
&#13;
&#13;
&#13;

PS p:selectOneMenu中的项目是对象。我为他们写了转换器

0 个答案:

没有答案