title: Programmatically adding selectonemenu
body: <p>I have a problem with adding selectonemenu component of Primefaces at runtime. 
  I added the selectonemenu but it doesnt display the name or attrbt of the objects , it shows references of them. 
  Thank you for your time .</p>
  
  
  
  <pre><code>&lt;ui:composition template="/pages/admin/admin.xhtml"
                  xmlns="http://www.w3.org/1999/xhtml"
                  xmlns:ui="http://java.sun.com/jsf/facelets"
                  xmlns:f="http://java.sun.com/jsf/core"
                  xmlns:h="http://java.sun.com/jsf/html"
                  xmlns:p="http://primefaces.org/ui"&gt;
  
      &lt;ui:define name="center"&gt;
          &lt;h:form id="openposition"&gt;
              &lt;h:panelGrid id="openpanelposition" columns="1"&gt;
                  &lt;p:outputLabel value="#{menu['menu.admin.openposition.name']}"/&gt;
                  &lt;p:selectOneMenu id="positiontype" value="#{openPositionController.position}" converter="#{positionConverter}" panelStyle="width:180px"
                                   effect="fade" var="u" style="width:160px" filter="true" filterMatchMode="startsWith"&gt;
                      &lt;f:selectItems value="#{openPositionController.positionList}" var="position" itemLabel="#{position.name}" itemValue="#{position}" /&gt;
                      &lt;p:column&gt;
                          &lt;h:outputText value="#{u.name}" /&gt;
                      &lt;/p:column&gt;
                  &lt;/p:selectOneMenu&gt;
                  &lt;h:panelGrid id="unitgroup" columns="1"&gt;
                      &lt;p:selectOneMenu id="higherunit" value="#{openPositionController.unit}" converter="#{unitConverter}" panelStyle="width:180px"
                                       effect="fade" var="unit" style="width:160px" filter="true" filterMatchMode="startsWith"
                                       valueChangeListener="#{openPositionController.selectunit}"&gt;
                          &lt;f:selectItems value="#{openPositionController.unitList}" var="unit" itemLabel="#{unit.unitName}" itemValue="#{unit}" /&gt;
                          &lt;p:ajax update="@this"/&gt;
                          &lt;p:column&gt;
                              &lt;h:outputText value="#{unit.unitName}" /&gt;
                          &lt;/p:column&gt;
                      &lt;/p:selectOneMenu&gt;
                  &lt;/h:panelGrid&gt;
              &lt;/h:panelGrid&gt;
          &lt;/h:form&gt;
      &lt;/ui:define&gt;
  
  &lt;/ui:composition&gt;
  </code></pre>
  
  
  
  <pre><code>package tr.com.innova.hrm.web.controller.menucontroller;
  
  /**
   * Created by mcan on 22/01/2015.
   */
  
  import org.primefaces.component.selectonemenu.SelectOneMenu;
  import org.primefaces.context.RequestContext;
  import tr.com.innova.hrm.model.entity.Position;
  import tr.com.innova.hrm.model.entity.Unit;
  import tr.com.innova.hrm.service.api.business.PositionService;
  import tr.com.innova.hrm.service.api.business.UnitService;
  import tr.com.innova.hrm.web.converter.UnitConverter;
  
  import javax.annotation.PostConstruct;
  import javax.el.ELContext;
  import javax.el.ExpressionFactory;
  import javax.el.ValueExpression;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.ManagedProperty;
  import javax.faces.bean.ViewScoped;
  import javax.faces.component.UISelectItems;
  import javax.faces.component.html.HtmlPanelGrid;
  import javax.faces.component.html.HtmlPanelGroup;
  import javax.faces.context.FacesContext;
  import java.io.Serializable;
  import java.util.List;
  
  @ManagedBean(name = "openPositionController")
  @ViewScoped
  public class OpenPositionViewController implements Serializable{
  
      private Position position;
      private Unit unit;
      private List&lt;Position&gt; positionList;
      private List&lt;Unit&gt; unitList;
  
      @ManagedProperty("#{positionService}")
      private PositionService service;
  
      @ManagedProperty("#{unitService}")
      private UnitService unitService;
  
      public UnitService getUnitService() {
          return unitService;
      }
  
      public void setUnitService(UnitService unitService) {
          this.unitService = unitService;
      }
  
      public Unit getUnit() {
          return unit;
      }
  
      public void setUnit(Unit unit) {
          this.unit = unit;
      }
  
      public List&lt;Unit&gt; getUnitList() {
          return unitList;
      }
  
      public void setUnitList(List&lt;Unit&gt; unitList) {
          this.unitList = unitList;
      }
  
      public Position getPosition() {
          return position;
      }
  
      public void setPosition(Position position) {
          this.position = position;
      }
  
      public List&lt;Position&gt; getPositionList() {
          return positionList;
      }
  
      public void setPositionList(List&lt;Position&gt; positionList) {
          this.positionList = positionList;
      }
  
      public PositionService getService() {
          return service;
      }
  
      public void setService(PositionService service) {
          this.service = service;
      }
  
      @PostConstruct
      public void init()
      {
          positionList = service.loadAll();
          unitList = unitService.getAllUnit();
          FacesContext.getCurrentInstance().getViewRoot();
      }
  
      public void selectunit()
      {
          HtmlPanelGrid component = (HtmlPanelGrid) FacesContext.getCurrentInstance().getViewRoot().findComponent(":openposition:unitgroup");
          SelectOneMenu oneMenu = new SelectOneMenu();
          oneMenu.setRendered(true);
          oneMenu.setConverter(new UnitConverter());
          UISelectItems items = new UISelectItems();
  
          ValueExpression expr = getValueExpression("#{openPositionController.unitList}");
          items.setValueExpression("value", expr);
          oneMenu.getChildren().add(items);
          component.getChildren().add(oneMenu);
  
          RequestContext context = RequestContext.getCurrentInstance();
          context.update("openposition");
          context.update("openposition:unitgroup");
      }
  
      private ValueExpression getValueExpression(String expression) {
          ExpressionFactory expressionFactory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
          ELContext expressionContext = FacesContext.getCurrentInstance().getELContext();
          return expressionFactory.createValueExpression(expressionContext, expression, Object.class);
      }
  }
  </code></pre>