hastybox/type-include-taglib
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
This is a simple implementation of a taglib that includes JSPs on given object types. It is basically an open source implementation of the basic functionality that CoreMedia provides with its cm:include Tag. This implementation however does not include "crazy" caching or whatever. The Taglib is included using using the following URI: http://hastybox.com/taglib/typeinc Simple usage example: Lets say you have the following class: class ArticleImpl extends ArticleBase implements Article {} The library first tries to include an appropriate JSP for the given class of the instance (ArticleImpl). If it could not find a JSP it searches for the Interface(s!!) (Article). And if that fails also it searches for a JSP for the super class (ArticleBase). Then the cycle starts again until it hits java.lang.Object and fails afterwards. The library includes two tags: include and param. The usage is similar to tags of the core library: <typeinc:include self="${object}" template="teaser" > <typeinc:param name="someParam" value="${someValue}"> </typeinc:include> The "self" attribute is mandatory as it contains the object which's type is evaluated and thus a JSP is included. The "template" attribute is optional and decides which object template is to be included (see example later) The param tag passes additional parameters to the included JSP. However parameters form parent JSP are also available as long as they are not overridden by the param tag. Default configuration: JSPs have to be placed in /WEB-INF/typeTemplates example JSPs /WEB-INF/typeTemplates/{package.name}/{classname}{.template}.jsp /WEB-INF/typeTemplates/com.hastybox/Article.jsp /WEB-INF/typeTemplates/com.hastybox/Article.teaser.jsp /WEB-INF/typeTemplates/java.lang/Object.jsp Custom configuration: If you like to store your templates in another folder than typeTemplates, you need to instantiate an IncludeService. By default a SimpleIncludeService is instantiated on the first call of a type-include tag with the basePath "/WEB-INF/typeTemplates/" (beware the closing "/"). The tag calls the static Method IncludeServiceFactory.getIncludeService() to retrieve a GoF-like singleton from the Factory class. If no IncludeService was defined previously a new SimpeIncludeService is created with default values. To define a custom path to your templates you need to create a new SimpleIncludeService and set the basePath either by setter or in the constructor. At last you need to define your instance as the singleton instance of the IncludeServiceFactory as the tags use the factory to retrieve the IncludeService. This is to be done by using the static method IncludeServiceFactory.setIncludeService(). This method returns the given IncludeService for convenience. If you would like to create your own IncludeService implementation you just need to implement the respective interface and pass the instance to the IncludeServiceFactory as described before. Spring configuration: Here is an example on how to instantiate your a custom IncludeService and publish it as the singleton to use. <bean class="com.hastybox.typeincludetaglib.path.IncludeServiceFactory" factory-method="setIncludeService"> <constructor-arg> <bean class="com.hastybox.typeincludetaglib.path.SimpleIncludeService"> <property name="basePath" value="/WEB-INF/somewhere/"/> </bean> </constructor-arg> </bean>