In my earlier article, Creating a CSS Based Fixed Page Layout, I've shown how to create your own Page Layout. In this article, I'll show how to add your Page Layout as a Netbeans template, so that it would appear in the New Visual Web Page Wizard for you to pick and create your page. We will be creating a plugin, which on installation will add your pre-defined Page Layout to the New Visual Web Page Wizard. The created plugin will be similar to the popular Netbeans plugin "Visual Web Page Layouts".
Download: Finished project for this plugin - PageLayoutTemplatePlugin.zip
Creating the Plugin
Creating a Netbeans plugin is extremely easy. It is a matter of few mouse clicks and key strokes. Let us start with creating a plugin project. Here are the steps

Netbeans creates the skeleton plugin project and loads it in the project explorer. You'd notice, Netbeans has created the several files including the package com.sample.pagelayouts. Expand this package and you'll see two important files
Adding contents to the plugin
Next step is to create the Netbeans template from the the Page Layout web page we created earlier, including JSP, Java and related resources. Let us place our template files in a folder called "resources".
We just copied and renamed the files PageLayout1.jsp.template and PageLayout1.java.template They are not templates yet. Next step is to convert them in to actual templates. Netbeans uses Free Marker templating Engine.
Converting to template file
Java File:
package com.sample.pagelayouts;with
<#if package?? && package != "">
package ${package};
</#if>
public class PageLayout1 extends AbstractPageBean {
with
public class ${name} extends AbstractPageBean {public PageLayout1() {
withpublic ${name} () {
JSP File:
The # (pound) symbol is a predefined special character for FreeMarker templating enginer. So we need to replace all # character with ${pound} template and tell the engine to replace it while instantiating the template. So at the top of the file insert the assignment as
<#assign pound = '#'>
<?xml version="1.0" encoding="UTF-8"?> <jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>with
<?xml version="1.0" encoding="${encoding}"?>
<jsp:directive.page contentType="text/html;charset=${encoding}"
pageEncoding="${encoding}"/><webuijsf:page binding="#{PageLayout1.page1}" id="page1">
with
<webuijsf:page binding="${pound}{${folder}${name}.page1}" id="page1">
Adding template information to layer file
Ok, we are ready with the templates. Now we need to put the info about these templates in to the layer file so that they would appear in the New Visual Web Page Wizard.
<filesystem>
<folder name="Templates">
<folder name="PageLayoutTemplates">
<file name="PageLayout1.jsp"
url="/com/sample/pagelayouts/resources/PageLayout1.jsp.template">
<attr name="SystemFileSystem.localizingBundle"
stringvalue="com.sample.pagelayouts.Bundle"/>
<attr name="name" stringvalue="PageLayout1" />
<attr name="icon"
urlvalue="nbresloc:/com/sample/pagelayouts/resources/
PageLayout1-icon.jpg" />
<attr name="previewImage"
urlvalue="nbresloc:/com/sample/pagelayouts/resources/
PageLayout1-preview.jpg" />
<attr name="resources"
urlvalue="nbresloc:/com/sample/pagelayouts/resources/
PageLayout1-resources.zip" />
<attr name="position" intvalue="10000"/>
<attr name="pageLayoutTemplate" boolvalue="true"/>
<attr name="description" stringvalue="PageLayout1_Desciption"/>
<attr name="javax.script.ScriptEngine" stringvalue="freemarker"/>
</file>
<file name="PageLayout1.java"
url="/com/sample/pagelayouts/resources/PageLayout1.java.template">
<attr name="position" intvalue="20000"/>
<attr name="javax.script.ScriptEngine" stringvalue="freemarker"/>
</file>
</folder> <!-- Page Templates -->
</folder> <!-- Templates -->
</filesystem>
Couple of things to note in the information we entered above
Folder: Template/PageLayoutTemplates - This is the pre-defined folder where the New Visual Web Page Wizard will look for new templates
File: PageLayout1.jsp (page) & PageLayout1.java (page bean) - These are the two actual templates that will be instantiated by the wizard.
Attributes:
PageLayout1=A simple nice my own Page Layout PageLayout1_Desciption=Creates page with my own very nice simple Page Layout
Testing the Plugin
You can test the plugin by directly installing it in the development IDE.

Creating the NBM
Finally, create the NBM to be installed using plugin manager. Right click on the project node and select "Create NBM". The Created NBM is placed in the build folder as com-sample-pagelayouts.nbm