// Prepare JPA Persistence Unit
context.put("persistenceUnitName", jpa.getConfig().getOrCreatePersistenceUnit().getName());
// Create the Backing Bean for this entity
JavaClassSource viewBean = Roaster.parse(JavaClassSource.class,
this.templateProcessor.processTemplate(context, this.backingBeanTemplate));
viewBean.setPackage(java.getBasePackage() + ".view");
result.add(ScaffoldUtil.createOrOverwrite(java.getJavaResource(viewBean), viewBean.toString()));
// Set new context for view generation
context = getTemplateContext(targetDir, template);
String beanName = StringUtils.decapitalize(viewBean.getName());
context.put("beanName", beanName);
context.put("ccEntity", ccEntity);
context.put("entityName", StringUtils.uncamelCase(entity.getName()));
setPrimaryKeyMetaData(context, entity);
// Prepare entityMetawidget
this.entityMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + "." + ccEntity));
this.entityMetawidget.setPath(entity.getQualifiedName());
this.entityMetawidget.setReadOnly(false);
this.entityMetawidget.setStyle(null);
// Generate create
writeEntityMetawidget(context, this.createTemplateEntityMetawidgetIndent, this.createTemplateNamespaces);
result.add(ScaffoldUtil.createOrOverwrite(
web.getWebResource(targetDir + "/" + ccEntity + "/create.xhtml"),
this.templateProcessor.processTemplate(context, this.createTemplate)));
// Generate view
this.entityMetawidget.setReadOnly(true);
writeEntityMetawidget(context, this.viewTemplateEntityMetawidgetIndent, this.viewTemplateNamespaces);
result.add(ScaffoldUtil.createOrOverwrite(
web.getWebResource(targetDir + "/" + ccEntity + "/view.xhtml"),
this.templateProcessor.processTemplate(context, this.viewTemplate)));
// Generate search
this.searchMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + ".example"));
this.searchMetawidget.setPath(entity.getQualifiedName());
this.beanMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + ".pageItems"));
this.beanMetawidget.setPath(viewBean.getQualifiedName() + "/pageItems");
writeSearchAndBeanMetawidget(context, this.searchTemplateSearchMetawidgetIndent,
this.searchTemplateBeanMetawidgetIndent, this.searchTemplateNamespaces);
result.add(ScaffoldUtil.createOrOverwrite(
web.getWebResource(targetDir + "/" + ccEntity + "/search.xhtml"),
this.templateProcessor.processTemplate(context, this.searchTemplate)));
// Generate navigation
result.add(generateNavigation(targetDir));
// Need ViewUtils and forge.taglib.xml for forgeview:asList
JavaClassSource viewUtils = Roaster.parse(JavaClassSource.class,
this.templateProcessor.processTemplate(context, this.viewUtilsTemplate));
viewUtils.setPackage(viewBean.getPackage());
result.add(ScaffoldUtil.createOrOverwrite(java.getJavaResource(viewUtils), viewUtils.toString()));
context.put("viewPackage", viewBean.getPackage());
result.add(ScaffoldUtil.createOrOverwrite(
web.getWebResource("WEB-INF/classes/META-INF/forge.taglib.xml"),
this.templateProcessor.processTemplate(context, this.taglibTemplate)));