Showing Parent Lookup Details with Edit Link

David posts on the JHeadstart Discussion Forum: on a page for editing an person, he wants to have a very condensed report of who the boss (manager) is together with a link,
on the same page as the base person (employee), so that he can use the link if
needed to edit the "boss". Other requirements are: 1) to display some differentiated columns (for example name, lastname, town,
country, ...) with their header for the boss and 2) more generally, having a similar look-and-feel of the page as other pages, and keeping
things clearly separated.

Here is my suggested solution, based on the HR schema that is also used in the JHeadstart Tutorial:
Manager Details with Edit Link Image: The lookup attributes of the manager are shown in a separate Item Region, together with a hyperlink that deeplinks to the page to edit the manager.<br>

The example has a link to the same group, but the solution described here works just as well if you link to another group. If you apply it, you will be using partial page rendering, deeplinking custom templates en custom properties, while only making some easy changes in JDeveloper.

How to show parent lookup details with an edit link

First change the relevant View Object in the Model project:

  1. Edit the ADF BC View Object for Employees and add the Entity for the Manager (check that the correct Entity Association is used in the bottom right corner of the panel).
  2. Add the desired lookup attributes you want to show of the Manager, and optionally rename them to make them easily recognizable.
  3. Ensure that the lookup attribute for the id of the Manager is not marked as Primary Key.
  4. Ensure that the SQL Query where clause performs an outer join if the manager relation is optional.
  5. Test the View Object with the ADF BC Tester
Now add a Generator Template and change the Application Definition in the ViewController project:
  1. Save the custom Velocity template {manilaSuite.gems.includeGem (26)} in a templates/custom folder of your ViewController project.
  2. Open the Application Definition, go to the Employees Group, and click the button to synchronize the items. This will add the new Manager Lookup attributes as items.
  3. Create a new Item Region for the Employees Group, and drag and drop the Manager Lookup items and the Employee item for changing the Manager to the new Item Region.
  4. Put in an appropriate Title for the region, set Columns to 1 and Width to 10%.
  5. Set the Depends On Item property (only visible in Expert Mode) for the Manager Lookup items to the Employee item that changes when you update the Manager (the ManagerId item in this case). This ensures that when you change the Manager, the lookup attributes are refreshed.
We will turn the Manager Lookup item that contains the id of the manager (not the ManagerId, but the EmployeeId of the manager entity) into an edit deep link. I will call this item the ManagerEmployeeId.
  1. In the Application Definition Editor, go to the ManagerEmployeeId item, and go to the Templates tab. Set the FORM_TEXT_INPUT template to the new template formDeepLink.vm you downloaded.
  2. Go back to the Properties tab, and set Custom Property 1 (only visible in Expert Mode) to the name of the group you want to link to (in this case Employees). You can put an explanation in Custom Property Description 1.
  3. Go to the Employees group, and set Type of Deep Linking (only visible in Expert Mode) to Query By Key Value.
  4. Set the Deep Linking Key Expression to the JSF EL expression #{param.EmployeesId}.
If you want to add a similar deeplink in a table layout, download {manilaSuite.gems.includeGem (27)} and use it as the TABLE_TEXT_INPUT template.

For more information about dependent fields, deep linking and custom templates, see sections 8, 9 and 10 of the JHeadstart Tutorial. See also the JHeadstart Developer's Guide chapter 3, section Customizing Page Layout Generation.

Note: in this case the deep link goes to the same group, but the technique also applies when linking to any other group.
In case you want to link to the same group, there is an alternative solution possible: instead of a deeplink, put an actionListener on the commandLink, to set the current row using setCurrentRowWithKey, setCurrentRowWithKeyValue or queryByKeyValue. Let the actionListener reference a suitable action binding, that you manually add to the page definition. If you uncheck the group property Clear Page Definition Before Generation?, your change will be preserved.


Post a Comment:
  • HTML Syntax: NOT allowed

Java EE Consultants - JHeadstart, ADF, JSF


« July 2016