0

I have a list that tells me the getters to access for all objects in my form. As I iterate through the list, how can I convert that variable into the getter to call on the object? I'm trying to do something like the following but this is not correct as this is looking for getGetter on myObject.

<c:forEach var="myObject" items="${myForm.objects}">
  <c:forEach var="getter" items="${myForm.getters}">
    <html:text property="${myObject.getter}"/>
  </c:forEach>
</c:forEach>

The reason I'm doing this is because I have a list of flex attributes for my object. I may only have a subset of the flex attributes defined. So the nested loop is iterating over the list of defined flex attributes. I'm not showing it here but in my code, I get the associated getter to call for the flex attribute.

Abhishek Nayak
  • 3,732
  • 3
  • 33
  • 64

1 Answers1

0

I used a scriptlet inside my loop to do what I need. On my object I added a method called getGetterValue that takes in a string that identifies the getter to call. The method compares the string to lookup the getter to call, and then returns the value of the getter.

<c:forEach var="myObject" items="${myForm.objects}">
  <c:forEach var="getter" items="${myForm.getters}">
    <%
      MyObject myObject = (MyObject)pageContext.getAttribute("myObject");
      String getter = (String)pageContext.getAttribute("getter");
      Object getterValue = myObject.getGetterValue(getter);
    %>
    <%= getterValue %>
  </c:forEach>
</c:forEach>