Generate jsf navigationrules with JHeadstart

3

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) :

<span lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">&lt;af:commandButton textAndAccessKey=&quot;#{nls['COPY_BUTTON_LABEL_DEPARTMENTS']}&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; action=&quot;copyDepartment&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id=&quot;DepartmentsCopyButton&quot;&gt;<br />&lt;/af:commandButton&gt;</span>

Generated by the velocity template :

<span lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span><span lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">&lt;af:commandButton textAndAccessKey=&quot;${JHS.nls (&quot;Copy button&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,&quot;COPY_BUTTON_LABEL_${JHS.current.group.name}&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,&quot;Make a copy of this ${JHS.current.group.displayTitleSingular}&quot; )}&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; action=&quot;copyDepartment&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id=&quot;${JHS.current.group.name}CopyButton&quot;&gt;<br />&lt;/af:commandButton&gt;</span>

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

<span lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span><span lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"></span><span lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">&lt;navigation-rule&gt;<br />&nbsp; &lt;from-view-id&gt;/pages/Departments.jspx&lt;/from-view-id&gt;<br />&nbsp; &lt;navigation-case&gt;<br />&nbsp;&nbsp;&nbsp; &lt;from-outcome&gt;copyDepartment&lt;/from-outcome&gt;<br />&nbsp;&nbsp;&nbsp; &lt;to-view-id&gt;/pages/DepartmentsTable.jspx&lt;/to-view-id&gt;<br />&nbsp; &lt;/navigation-case&gt;<br />&lt;/navigation-rule&gt;</span>

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")}".

Share.

About Author

Aino Andriessen is a consultant on Enterprise Java, ADF, PL/SQL, XML, and SOA development and is Expertise Lead on Application Lifecycle Management (ALM). He has a strong interest in ADF, SOA, Maven, architecture, quality management, delivery and application lifecycle management. Aino publishes on the AMIS technology blog and has been a presenter at the ODTUG Kaleidoscope, Oracle Open World and UKOUG TechEbs.

3 Comments

  1. Aino, good explanation!

    Did you know that the feature of generating navigation rules is also described in the JHeadstart Developer’s Guide of October 2006 at http://download.oracle.com/consulting/jhsdevguide1013.pdf? See chapter 3 – JHeadstart Application Generator – Customizing Page Layout Generation – Using Generator Templates – Generating a JSF Navigation Rule from a Generator Template.

    There is also a section about Generating a JSF Managed Bean from a Generator Template.

    kind regards, Sandra

  2. Aino Andriessen on

    You can view the local (i.e. JDeveloper) history of a file on the History tab, underneath the file, next to the Design and Source tab. It can be configured (only a bit) with ‘preferences -> Environment -> Local History’.

  3. Very good post! Shows the power of the JHeadstart templating mechanism, and your command of taking it to the limits.

    (by the way, how do you get the history of files to be available)

    thanks,.

    Lucas