Reputation: 951
Im a little new to JSTL and Javabeans so I'm having a lot of trouble figuring this one out.
I have an index.jsp, a class called CustomerScheme which extends an ArrayList, and a test.jsp which im using for output.
index.jsp contains the following code, and has a link to test.jsp:
<jsp:useBean id="scheme" scope="session" class="customer.beans.CustomerScheme">
<%
// Open a stream to the init file
InputStream stream =
application.getResourceAsStream("/fm.txt");
// Get a reference to the scheme bean
CustomerScheme custScheme =
(CustomerScheme) pageContext.findAttribute("scheme");
// Load colors from stream
try {
custScheme.load(stream);
} catch (IOException iox) {
throw new JspException(iox);
}
%>
</jsp:useBean>
test.jsp contains:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
${scheme.size}
CustomerScheme extends ArrayList, and has the method:
public int getSize() {
return this.size();
}
CustomerScheme has more code. I'll post it if you need.
My problem is this: Whenever I run the program, I start at index.jsp, click the link to go to test.jsp, and then get the following:
Upvotes: 2
Views: 1076
Reputation: 289
If you don't want to create an extra wrapper class you can do the following:
<c:set var="size"><jsp:getProperty name="scheme" property="size"/></c:set>
size : <c:out value="${size}"/>
Upvotes: 0
Reputation: 94643
The javax.el.ListELResolver
handles base objects of type java.util.List
. It accepts any object as a property and coerces that object into an integer index into the list.
So you need to call the getSize()
method - ${scheme.getSize()}
or use <jsp:getProperty/>
Alternatively, you can create a List<T>
in customer.beans.CustomerScheme
instead of extending ArrayList<T>
.
public class CustomerScheme{
private List<Customer> list=new ArrayList<Customer>();
public int getSize(){
return list.size();
}
..
}
Upvotes: 2