Using JHeadstart createModes for rendered expression and in java backend

When pressing a ‘New’ button, the ‘Create’ action binding is executed and the onCreate() method in JhsPageLifecycle fires. This method stores an entry in the managed bean Hashmap called createModes, with the name of the Create action binding as the key, and Boolean.TRUE as the value.

As a result of this, the following expression can be used to check whether the Departments group is in create mode:

#{createModes.CreateDepartments}

Note that JHeadstart always suffixes the name of the Create binding with the group name, to prevent duplicate binding names when multiple groups are displayed on the same page.
With this knowledge you will understand the expression that is used to display the
correct page title:

<af:panelPage title=”#{createModes.CreateDepartments ? nls['INSERT_TITLE_DEPARTMENTS'] : nls['EDIT_TITLE_DEPARTMENT:#{bindings.DepartmentsDepartmentName}']}”>

And the rendered property of the New and Delete buttons looks simply like this:

rendered=”#{!createModes.CreateDepartment}”

When you press Save in the form page, the onCommit() in JhsPageLifecycle is called, and this method will remove all entries from the createModes managed bean Hashmap hen commit is successful.

JHeadstart Developer Guide 1013 Chapter 5.1.3. Create and Update Mode in Form Layout

You can also access creatModes directly from the session bean. So you can use it in your businesslogic for conditional actions you want to invoke.

Code to get the HashMap from the session bean:

//get FacesContext
FacesContext context = FacesContext.getCurrentInstance();

//get JhsCreatenmode
HashMap createMode = (HashMap)context.getExternalContext().getSessionMap().get("createModes");
Boolean creJhsGroupName = (Boolean)createMode.get("CreateJhsGroupName");

//condition
if  (check == true && creJhsGroupName.booleanValue() == true) {
//do this
} else {
//do that
}

About this entry