I want to implement custom JSP list tag, but have problem with accessing properties of custom list object. With example like below accessing a name
property of List2
on test.jsp
page give an error org.apache.jasper.JasperException: java.lang.NumberFormatException: For input string: "name"
. How to solve this ?
public class List2 extends ArrayList<String> {
public String getName() {
return "name";
}
}
test.jsp
<%-- java.lang.NumberFormatException --%>
${list.name}
<%-- this works ok --%>
<c:forEach items="${list}" var="item">
${item}
</c:forEach>
EDIT
Whole test.jsp
working
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:forEach items="${list}" var="item">
${item}
</c:forEach>
Whole test.jsp
NOT working
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
${list.name}
TestController.java:
@Controller
public class TestController {
@ModelAttribute("list")
public List2 testList() {
List2 l = new List2();
l.add("foo");
l.add("bar");
return l;
}
/* test.jsp */
@RequestMapping("/test")
public String test() {
return "test";
}
}