0

I want to use ui:repeat to fill values of an integer array which is originally empty, from inputText. I followed the explanation in here, but it did't work for me. My UI is:

<ui:repeat value="#{controllerBean.schedule.scheduleTimes}" var="v" varStatus="loop">
    <h:outputText value="Shedulte Time #{loop.index + 1}">
    </h:outputText>
    <p:inputText value="#{controllerBean.schedule.scheduleTimes[loop.index]}">
    </p:inputText>
</ui:repeat>

contollerBean is the managed bean, schedule is model and scheduleTimes is Integer[] array in my model with setter and getter. After providing some values on ui, the values of the array at each index is still null.

1 Answer 1

0

You need a converter to Integer because in JSF all values are by default treated as String.

<ui:repeat value="#{controllerBean.schedule.scheduleTimes}" var="v" varStatus="loop">
    <h:outputText value="Shedulte Time #{loop.index + 1}">
    </h:outputText>
    <p:inputText value="#{controllerBean.schedule.scheduleTimes[loop.index]}" converter="javax.faces.Integer">
    </p:inputText>
</ui:repeat>

Now the example works for me like a charm.


My previous answer is incorrect because JSF automatically converts primitive types. A converter is however required for Collections because expected type cannot be determined at runtime.

Nevertheless the example works with a converter or without. Therefore please make sure that controllerBean has scope other than non-scoped (without scope annotation). Otherwise the bean is recreated each time you access it.


Well, also with request scope my code works fine. Please check the example I'm using

I replaced primefaces p:inputText with pure JSF h:inputText but I don't think it matters. I also added some html table tags to do a formatting.

As you can see in server logs values are set properly.

Sign up to request clarification or add additional context in comments.

4 Comments

Yes, your previous answer didn't work. I am using request scope for the bean.
I updated my answer with example project that I'm using. Maybe you can compare your project with mine and spot some difference.
I appreciate your effort Dawid. Your code works fine. But, I discovered that my problem is related to the size assignment of scheduleTimes array. I want to accept its size from selectOneMenu using valueChangeListener, create the array based on this value on value change, and then use it on the ui:repeat. The problem i think is b/c the array is created after the construction of managed bean.
I have changed bean to view scoped and now works. Sorry for not explaining the details...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.