ulquiorra
ulquiorra

Reputation: 945

The UISelectMany value should be an array or a collection type, the actual type is java.lang.String

I have a selectmanylistbox filled with List and i got the error "Target model Type is no a Collection or Array" (and "The UISelectMany value should be an array or a collection type, the actual type is java.lang.String" in the console) when i try to submit my form despite i am using a collection ...

Thank you very much for your help

jsf page :

<td>People list</td>
<td>
    <h:selectManyListbox value=" #{people.selectedPeople}" size="3">
        <f:selectItems value="#{people.peopleList}"/>
    </h:selectManyListbox>
</td>

My managed bean

@ManagedBean(name="people")
@RequestScoped

public class People implements Serializable {
    private static final long serialVersionUID = 1L;

    private List<String> peopleList;
    private List<String> selectedPeople;


    public People(){        
        peopleList = Arrays.asList("one", "two", "three", "four", "five");
    }

    // getters , setters
}

Upvotes: 2

Views: 2457

Answers (1)

RevanProdigalKnight
RevanProdigalKnight

Reputation: 1326

In your <h:selectManyListbox> your value should be an array of Strings. JSF doesn't like using Lists for that, for some odd reason. I know this because I just had a similar problem the other day with a <p:selectManyCheckbox> in PrimeFaces.

If you change from private List<String> selectedPeople; to private String[] selectedPeople; (and change the getters and setters as necessary) it should work.

EDIT: Failing that, I just noticed that you have a space in value=" #{people.selectedPeople}" which may also be part of the problem.

Upvotes: 4

Related Questions