Search code examples
jsffaceletsuirepeat

JSF - Is it possible to list some bean attributes via reflection using c:forEach or ui:repeat?


Suppose I'd like to do something like this

<ui:repeat value="#{myMB.fields}" var="field">
<p:outputLabel for="#{field}" value="#{field}:" style="width:100px;"/>
<p:outputLabel id="#{field}" value="#{my.someobject.#{field}}"/>
</ui:repeat>

"fields" are the attributes of some bean (can be retrieved using reflection or not)

is it possible to be done using c:forEach or ui:repeat?


Solution

  • You should be able to do with ui:repeat no problem:

    <ui:repeat value="#{myMB.fields}" var="field">
      <p:outputLabel for="#{field.some_id}" value="#{field.some_value}:" style="width:100px;"/>
      <p:outputLabel id="#{field.some_id}" value="#{my.someobject.#{field.value}}"/>
    </ui:repeat>
    
    public class myMB {
    
      List<Field> fields = new ArrayList<Field>();
    
      // Constructor
      public MyMB() {
        // Set some values in fields 
      }
    
      // Getters and Setters
    }
    
    public class Field {
        int some_id = 10;
        String some_value = "Something"
    
        // Getters and setters
      }
    

    Is that what you're asking?