0 Replies Latest reply on Mar 5, 2010 4:11 PM by amayingenta

    Editing a List<String> in a datatable

    amayingenta

      In my hibernate model I have a List<String> annotated as a @CollectionOfElements. I want to be able to edit this collection (it's a list of goals - each goal being a 100 character h:textInput) in a datatable, with the ability to add and remove goals.


      Similar things work fine when I've had a collection of other entities and edited their attributes, but the same approach doesn't seem to work for this. I can add and remove rows, but any updates I make in the form are never saved.


      <rich:dataTable id="goalsTable" value="#{course.goals}" var="goal" rowKeyVar="rownum">
          <h:column>
              <f:facet name="header">Goal</f:facet>
              <h:inputText id="goal" value="#{goal}" maxlength="100"/>
          </h:column>
          <h:column>
              <f:facet name="header">Action</f:facet>
              <a4j:commandButton id="addGoal" value="Add Goal" action="#{course.getGoals().add(ronum, '')}" reRender="courseDetailsPanel"/>
              <a4j:commandButton id="removeGoal" value="Remove Goal" rendered="#{course.goals.size() > 1}"
                                 action="#{course.goals.remove(ronum)}" reRender="courseDetailsPanel"/>
          </h:column>
      </rich:dataTable>
      



      I suspect this isn't going to work because I'm trying to update the value that's also what I'm iterating, but short of creating a Goal entity that wraps the String value I'm not sure if there's a better way of doing this.


      Anyone got any ideas?
      Thanks, Andrew