How to set selected value into p:selectOneMenu?

UI Components for JSF
Post Reply
TenebrisFenix
Posts: 1
Joined: 03 Jul 2015, 10:26

03 Jul 2015, 10:54

Primefaces 4.0
Apache Tomcat 8.0
JSF 2.1

I have p:selectOneMenu:

Code: Select all

<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>   
I need to set value via javascript. In the web I found this solution:

widgetVar.selectValue(value);


I apply it to my case:

Code: Select all

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
}
Items in p:selectOneMenu are objects(CategoryEntity type). I wrote converter for them.
I think that is a problem.
In my opinion here categoryListWV.selectValue(parent); parent should be CategoryEntity type( now it is String).

Can it be fixed or easier will be create String list instead CategoryEntity list?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 32 guests