0

I want to dynamically create a SelectOnListBox in JSF (Primefaces), but I don't know how to fill in the values with "Verde" and "Azul"

    FacesContext fCtx = FacesContext.getCurrentInstance();
    ELContext elCtx = fCtx.getELContext();
    ExpressionFactory ef = fCtx.getApplication().getExpressionFactory();
            
    getL_valores().put("Verde", "Verde");
    getL_valores().put("Azul", "Azul");
    
    
    javax.faces.component.html.HtmlSelectOneListbox lista = new  javax.faces.component.html.HtmlSelectOneListbox();
    lista.setRendererType("javax.faces.Listbox");
    lista.setId("variacion1");
    
   
    lista.setValue(getL_valores());
    lista.setLabel("lista1");
    
    dynamicFieldGroup = new HtmlPanelGrid();
    dynamicFieldGroup.setColumns(4);
    
    dynamicFieldGroup.getChildren().add(lista);        
    

This is my xhtml

 <h:form id="Form1">
        <p:panelGrid columns="2" binding="#{b_detalle_productos.dynamicFieldGroup}"></p:panelGrid>
        
    </h:form>
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • So if you use an `h:panelGrid` it works? If not it is not PrimeFaces related. And checked https://stackoverflow.com/questions/3409053/how-to-dynamically-add-jsf-components and all links in it? – Kukeltje Aug 20 '20 at 21:42
  • The question is : how add values to SelectOneListBox component? – Santiago Matiz Aug 20 '20 at 22:08
  • I know what your question is, sorry I did not mention that. But there is rearely a need to create components like this in java. That is what the link I posted (and the links in it) are about. Way more complicated to do this in java than in xml (xhtml) – Kukeltje Aug 20 '20 at 22:39

0 Answers0