When you create pages at runtime, you can also select a template for those pages. The templates you create in JDeveloper at design time are not available for the pages created at runtime. That's why you also need to create templates in runtime.
When you create a template at runtime, you need to specify an existing template as a reference. This way, you don't need to start with an empty template.
This recipe requires a WebCenter portal application.