Reputation: 21
I'm developing a web application using Spring MVC 3.2.4 (Spring Core 3.2.4 too) with jpa & hibernate for the back-end. And currently using Tomcat v6.0 for testing.
I had a case when i created a JSP custom tag lib (using jsp-api 2.1.1 & servlet-api 2.5), which is a custom lookups drop down list, i would give it the lookup type, and it would get from the DB the items under this type to render as items in the list.
The custom taglib class basically looks like something similar to this:
public class LookupsTag extends SimpleTagSupport {
@Autowired
private static LookupService lookupService;
private String type;
public void doTag() throws JspException, IOException {
List<Lookup> items = lookupService.findByType(getType());
StringBuffer buff = new StringBuffer();
buff.append("<select>");
//...adding items...
buff.append("</select>");
getJspContext().getOut().write(buff.toString());
}
//getters and setters
}
And i have created the tld file accordingly and all.
Once i attempt to view a page using this custom tag, a NullPointerException is thrown because inside the doTag() method, the lookupService instance is null.
Spring doesn't seem to support custom jsp tags. Is there a way to work around this to make the service instance autowired automatically? Or am i missing some spring configurations to do?
Thanks,
Upvotes: 1
Views: 1536
Reputation: 21
Thanks to Alan Hay on his comment, custom jsp taglib will not be supported. Spring is already providing what i needed through their taglib http://docs.spring.io/spring/docs/current/spring-framework-reference/html/spring-form.tld.html#spring-form.tld.select
Upvotes: 0