Using JSP templates without the OpenCms taglib
In the previous steps you learned how to use JSP based templates with the OpenCms
If you want to create a scriptlet based JSP without using the taglib, there is another way to include template elements in
your JSP. This is achieved by the JavaBean
org.opencms.jsp.CmsJspActionElement . This
Bean provides direct access to the functionality offered by the OpenCms taglib.
It is described in detail in the
Here's a simple JSP that uses the template from the previous example without the taglib (check out the file example-jsp-template-action.jsp to see this in action):
// create a JSP action element
org.opencms.jsp.CmsJspActionElement cms =
new org.opencms.jsp.CmsJspActionElement(pageContext, request, response);
// load the template head
// generate some output
// load the template foot
here needs two String parameters, the first
is the path and filename to the included JSP template, the second the name of
the selected element. Instead of writing the name of the JSP template file
directly in your JSP like we did in this example, you can also combine the
methods of the CmsJspActionElement. For
you can use the method
which returns the value of the "template" property if you attached
this to the JSP (or a parent folder). This way you can achieve exactly the same result
as using the
<cms:include property="template" file="search" />
tag from the OpenCms taglib.
Whether you prefer using the taglib or the Java Bean is a matter of application (or taste). Both options execute the same code inside OpenCms. It is up to you to make your choice.
After working through this howto, you should be able to create your own JSP based templates in OpenCms. JSP based templates can be used for "editable" HTML pages and also for "dynamic" JSPs as outlined in our examples. Of course, not all options of the OpenCms taglib or scriptlet API available to build templates with have been explained in detail here. You should consult the reference modules for this libraries for more in-depth information.