Search code examples
jsffaceletsuirepeat

How to save an array in JSF with ui:repeat + h:inputText + managed bean?


In a postgres database I have a table with, among others, an int[] field.

In my model I have a persisted bean that maps the table, including the int[] field. In this class I have implemented all the needed setters/getters.

Now, I have a managed bean which plays also the controller role, and links to the model bean. So, in my xhtml I'm trying to do this:

<ui:repeat value="#{drawsetController.selected.editableBaseSetList}" var="baseNumber">
    <h:inputText value="#{baseNumber}"/>
</ui:repeat>

baseSetList is the int[] array.

The problem is that when I submit my form only this element is not updated. The initialization is working, the getter is called, but not the save, so it must be a bind thing. Long story short, I have tried to replace the int[] array with an ArrayList of a custom class which could wrap the int (like a writable Integer) but it isn't working.

Maybe It's the repeat that doesn't bind properly, I don't really know. This is my first project in java after years and years of PHP :).


Solution

  • Don't know if I get you right, but baseNumber is not bound to any property in any managed bean. It only exists in the scope of ui:repeat.

    You should do something like:

    <ui:repeat value="#{editableBaseSetList}" var="myVariable">
        <h:inputText value="#{managedBean.property}" />
    </ui:repeat>