Generate jsf navigationrules with JHeadstart

The templating mechanism of JHeadstart is a huge improvement over the previous versions. It is now quite easy to add your postgeneration changes to a velocity template and add it to the generation again: no more postgeneration. But there are a few things to be aware of : 1. postgeneration to the pagedefinition cannot be templated 2. take care of your custom nls generated text, as described in an earlier post and 3. custom navigation rules cannot be generated…

…or can they?

For navigation to another page you can rely on the existing navigationrules that are defined (actually generated) in the faces-config.xml, but it may be better to introduce your own. For example when you want to return to the overview (table) page after you made a copy of the current Department.

The commandButton would look like this (I’ll leave out the actionListener that performs the actual method) :

<af:commandButton textAndAccessKey="#{nls['COPY_BUTTON_LABEL_DEPARTMENTS']}"

Generated by the velocity template :

<af:commandButton textAndAccessKey="${JHS.nls ("Copy button"
                                              ,"Make a copy of this ${}" )}"

And the manual added the navigationRule in the faces-config.xml looks like :


However, after generation, the rule is gone and must be added again. By the way, using the history of a file makes it really easy to add it again :The design editor shows the difference between two versions


It would be much easier if we could include this rule in the generation process. One option is to add the rule to the faces-config.vm template. But we have now made additions to two templates that we have to maintain. It may be better if could somehow combine the action and the navigationrule in one template. This can be accomplished with the JHeadstart application generator method addGlobalNavigationCase and use that in our template, the action now looks like :

action=”${JHS.facesConfigGenerator.addGlobalNavigationCase(“CopyDepartment”, “DepartmentsTable”)}”

This method creates the global navigation (actually it adds it to the stack so that its generated later in the generation process) and returns the from-outcome. If you don’t like the global navigationcase, use the addNavigationCase method :


action=”${JHS.facesConfigGenerator.addNavigationCase(“Department”, “CopyDepartment”, “DepartmentsTable”)}”.



  1. Sandra Muller December 14, 2006
  2. Aino Andriessen December 14, 2006
  3. Lucas Jellema December 13, 2006