0

I have a edit screen which displays a series of editable properties(fields) of an entity. And this list of fields are dynamic,in the sense that any field can be added/removed from the list without any code change. I have a model something like this.

public class Property{

 private String displayName;
 private String value;
 private int displayOrder;
 //other props,getters,setters etc..
}

My backingBean has a map of these properties (for some other reasons,we chose map as the datastructure).

public class BackingBean{

private Map<String,Property> editableProps;
//other props,getters,setters etc..
}

The problem is with iterating over this map and produce a textbox for each of the entry. Since a4j:repeat(richfaces) doesn't iterate over a map,I have decided to use JSTL and the code fragment looks something like this,

<c:forEach items="${mybean.editableProps}"
                var="item" >
    <tr>
     <td>
      <c:out value="${item.value.displayName}"/>
     </td>
     <td>
      <input type="text" value="${item.value.value}" />
     </td>
    </tr>
</c:forEach>

This will work fine except for the fact that the binding of a ui field to bean's property will not happen automatically. If I try using h:inputText inside c:forEach, the component doesn't get rendered.(Guess the jstl var is not available for the jsf). Is there a JSF way of doing all this(Using hashmap)?So that a textbox is produced for each entry in the map and any change to it gets bound the underlying java bean property.?

chedine
  • 2,384
  • 3
  • 19
  • 24

1 Answers1

0

The proposed code woudl work in current versions of JSF. But also, an easier way to achieve this nowadays is to make your bean a map itself.

@Component("prop")
public class PropertyBean extends HashMap<String, Property>{
    public PropertyBean() {
        this.put("prop1", property1);
        this.put("prop2", property2);
    }
}

And in the facelets

<h:outputText value="#{prop.prop1.displayName}" />
<h:outputText value="#{prop.prop1.value}" />
Fabricio Buzeto
  • 1,243
  • 1
  • 18
  • 29