lets say i have a table test
with columns id
and name
on my bean i got this query
public List getTestList(){
Query q = em.createNativeQuery("select * from test");
List list = q.getResultList();
return list;
}
and on my jsf page i have:
<ul>
<ui:repeat id="resulta" value="#{testController.testList}" var="item">
<li>#{item.id}</li>
</ui:repeat>
</ul>
why do i get a SEVERE: javax.el.ELException: /test.xhtml: For input string: "id"
why do i get a SEVERE: javax.el.ELException: /test.xhtml: For input string: "id"
Because a native query returns a List<Object[]>
, not a List<Test>
. You're basically attempting to access an Object[]
array using a string such as "id"
as index instead of an integer such as 0
. If you look closer to the stack trace, then you should have noticed the presence of ArrayELResolver
a little further in the stack after the exception, which should already have hinted that #{item}
is actually been interpreted as an array.
So, if you absolutely can't obtain it as a fullworthy List<Test>
(you can easily do inner joins using @ManyToOne
and so on), then this should do to obtain the first column from the SELECT
query:
<li>#{item[0]}</li>