One of the most awesome features of Netbeans is to generate code using some FreeMarker templates. I have some questions about it, I hope someone here can help me.
How can I make a template on Netbeans that generates more than just 1 file?
For example, I use the "JSF Pages From Entity Beans" wizard to generate CRUD files. So it creates automatically 4 files for each entity I have:
- Create.xhtml
- Edit.xhtml
- List.xhtml
- View.xhtml
This is very useful, because you often needs to create, edit, list or view some records from your database. So I know I can edit each template individually by clicking on Tools -> Templates -> JavaServer Faces -> JSF entity -> View.xhtml. And then I can change the way View.xhtml is generated. Then a FTL file is created on "C:\Users\yourname\.netbeans\6.9\config\Templates\JSF\JSF_From_Entity_Wizard\view.ftl".
But I want more, I need also a Search page. My question is how can I make or change a template like "JSF Pages From Entity Beans" that generates not only 1 file, but 4 for each entity. So I can change this template to generate 5 files:
- Create.xhtml
- Edit.xhtml
- List.xhtml
- View.xhtml
- Search.xhtml (for example)
Thanks in advance!
You could create your own project template. Here's some instructions for doing that:
http://netbeans.dzone.com/tips/hack-your-own-custom-project-t
So, you could create a new project and use the "JSF Pages From Entity Beans" wizard and then add your own files. Then you would follow from step 2 of the above link and create the template.
Edit After giving this some more thought I think that what you're really looking for is creating a File Template Module:
http://platform.netbeans.org/tutorials/60/nbm-filetemplates.html
Edit 2: Based on your comment I'm posting a url to Geertjan's blog for a short description on how to create multiple files from a single wizard*. However, after more reflection I understand that this is also not what you want. What you really want is the ability to add another file to an existing wizard (JSF from Entity). This is of course possible but not as simple as creating your own wizard as the only way to do such a thing is to modify the source code for that particular module (JSF Support).
*Understand that the above tutorial is showing only a snippet of how to create your own New File wizard. There are a few aspects that are assumed to be understood already and not discussed.
来源:https://stackoverflow.com/questions/8157043/how-to-make-netbeans-templates-that-creates-more-than-1-file