In the previous steps you learned how to use JSP bases templates with the OpenCms <cms:>
taglib.
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 com.opencms.flex.jsp.CmsJspActionElement
. This Bean provides direct access to the functionality offered by the OpenCms taglib. It is described in detail in the com.alkacon.documentation.documentation-scriptlet
module.
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 com.opencms.flex.jsp.CmsJspActionElement cms = new com.opencms.flex.jsp.CmsJspActionElement(pageContext, request, response); // load the template head cms.include("/system/modules/com.alkacon.documentation.howto-template/jsptemplates/howto-complete.jsp", "head"); // generate some output out.println(new java.util.Date()); // load the template foot cms.include("/system/modules/com.alkacon.documentation.howto-template/jsptemplates/howto-complete.jsp", "foot"); %>
The include()
method 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 example you can use the method cms.property("template", "search")
which returns the value of the "template" property if you attached this to the JSP (or a parent folder). This way you can achive the exact same result as when 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 couse, 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.
]]>
In the previous steps you learned how to use JSP bases templates with the OpenCms <cms:>
taglib.
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 com.opencms.flex.jsp.CmsJspActionElement
. This
Bean provides direct access to the functionality offered by the OpenCms taglib.
It is described in detail in the com.alkacon.documentation.documentation-scriptlet
module.
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 com.opencms.flex.jsp.CmsJspActionElement cms = new com.opencms.flex.jsp.CmsJspActionElement(pageContext, request, response); // load the template head cms.include("/system/modules/com.alkacon.documentation.howto-template/jsptemplates/howto-complete.jsp", "head"); // generate some output out.println(new java.util.Date()); // load the template foot cms.include("/system/modules/com.alkacon.documentation.howto-template/jsptemplates/howto-complete.jsp", "foot"); %>
The include()
method
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
example
you can use the method cms.property("template", "search")
which returns the value of the "template" property if you attached this to
the JSP (or a parent folder). This way you can achive the exact same result as
when 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 couse, 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.
]]>