Search code examples
jsfimmutabilityicefacestextinputrepeat

ice:repeat inputText with List<String>, if String is immutable?


I want list to be List<String>. First I display one inputText, each time a user enters data in the inputText I add another empty inputText. If the list already has some values I display them all + one empty one.
But it doesn't work, because Strings are immutable.
I made a wrapper for String as an workaround, but I don't like it.
How could I make the inputText refer to the position in the backed list ?

<ice:repeat value="#{mBean.list}" var="xxx" valueChangeListener="{mBean.vcl}">
    <ice:inputText partialSubmit="true" value="#{xxx}" />
</ice:repeat>

Solution

  • I don't do IceFaces, but if the <ice:repeat> supports a varStatus attribute like as JSTL's <c:forEach> and Facelets' <ui:repeat>, then you can submit to a List<String> when accessing the individual item by list index instead of by var attribute as the following Facelet example:

    <ui:repeat value="#{bean.strings}" varStatus="loop">
        <h:inputText value="#{bean.strings[loop.index]}" />
    </ui:repeat>
    

    This way the value is set by the setter of the list, the List#set(index, value) method.

    Other than that, your best bet is really to wrap the String in a bean. I'm however pretty positive that JSTL <c:forEach> should also work out for you the above way, as long as you don't have it nested in another JSF repeating tag. You'll only miss that valueChangeListener attribute/feature you had in <ice:repeat>.