I am trying to write a JSP 2.0 tagfile which will accept an object of a non-library Java type as an attribute.
For example:
package org.myapp.model: Question.java
public Class Question {
private String name;
private String type;
public getName() { return name; }
public getType() { return type; }
...
}
displayQuestion.tag
<%@ tag body-content="empty" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ attribute name="question" required="true" type="org.myapp.model.Question"%>
<h2>
<div>Question ${question.name} is of type ${question.type}</div>
</h2>
When I deploy my webapp I get an error: ‘Unknown attribute type (org.myapp.model.Question) for attribute question.’ If I leave off the type it defaults to String, and of course question.name and question.type fail. What am I doing wrong?
Did you try adding import to the tag?