Reputation: 33
I'm using the JSTL SQL tag library to perform small SQL queries from within a JSP.
I normally retrieve the query results in EL by using rowsByIndex and then iterating over the returned collection:
<c:forEach var="row" items="${myQuery.rowsByIndex}">
<p>${row[0]}, ${row[1]}, ${row[2]}, ${row[3]}</p>
</c:forEach>>
I want to do something similar for the column names.
I see that there is a method on the result interface:
public String[] getColumnNames();
and I'm trying to figure out how to access this from EL.
I'm trying to do something like:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
...
<table>
<tr>
<c:forEach var="columnName" items="${helloQuery.getColumnNames}">
<th><c:out value="${columnName}" /></th>
</c:forEach>
<tr>
</table>
...
But no joy..
Upvotes: 1
Views: 1466
Reputation: 1109132
EL relies on the Javabeans specification and its naming conventions when it comes to accessing properties. You basically only need to specify the property name (even though it's virtual) and EL will turn it into a getter call when the value needs to be returned, or into a setter call when the value needs to be set (in JSF #{}
syntax only though).
So, ${helloQuery.getColumnNames}
is basically trying to invoke getGetColumnNames()
method on the class represented by ${helloQuery}
. But there is none and this would result in a PropertyNotFoundException
. You need to change it to ${helloQuery.columnNames}
in order to invoke the getColumnNames()
method.
Upvotes: 1