2017-06-15 75 views
-1

我收到错误:从XHTML文件javax.faces.FacesException:价值必须是一个数组或一个集合

javax.faces.FacesException: Value of 'frmrapport:type' must be an array or a collection

<p:selectManyMenu id="type" required="true" 
     value="#{userReporting.getTypeParId(userReporting.selected)[0].nomType}"> 
    <f:selectItem itemLabel="co" itemValue="co" /> 
    <f:selectItem itemLabel="pi" itemValue="pi" /> 
    <f:selectItem itemLabel="si" itemValue="si" /> 
</p:selectManyMenu> 
从Java bean的

public List getTypeParId(int id){ 
    return this.genTypeFacade.getTypeParId(id); 
} 

问题是豆是List,我无法将列表转换为String[]

+1

如果问题是“如何将列表转换为字符串[]”,则它是重复的**和**,非常容易在Internet和SO上查找。但我相信这不是你真正的问题。 – Nathan

回答

-1

userReporting.getTypeParId(userReporting.selected)正在返回List。您不能访问List[0],您必须使用List#get(int index)

value="#{userReporting.getTypeParId(userReporting.selected).get(0).nomType}" 

而且,使用泛型来carefult:你的方法getTypeParId返回超过1种类型:如果您指定的内容包含您返回集合,即:

public List<Type> getTypeParId(int id){ 
    return this.genTypeFacade.getTypeParId(id); 
} 

另一个“还”这是更好?如果是的话,应该叫getTypesParId

+0

你的回答比我的更正,我最好删除我的答案。 – hamena314

+0

@ hamena314你可以放过它,因为它回答了TO的问题;不是问题,而是问题:p – Nathan

+0

javax.faces.FacesException:'frmrapport:type'的值必须是数组或集合 –

相关问题