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

StackOverflow https://stackoverflow.com/questions/20981062

  •  25-09-2022
  •  | 
  •  

Question

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?

Was it helpful?

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top