2017-06-15 70 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'的值必須是數組或集合 –

相關問題