How to dynamically create commandNavigationItem at runtime
I you want to make a dynamic navigation Pane like this
when you click on the tree node on the right side, the page fragment on the left side is populated dynamically at runtime with a navigationPane.The commandNavigationItems are rendered at runtime. To do this , follow theses steps:
1- you must have a database table that stores the data of the commandNavigationItem like this
CREATE TABLE SMM_SYS_OBJECTS
(
ID NUMBER(10) NOT NULL,
OBJECT_REASON VARCHAR2(3 BYTE) DEFAULT 'REP' NOT NULL,
OBJ_SEQ NUMBER(3),
FILE_TYPE VARCHAR2(1 BYTE) DEFAULT 'M' NOT NULL,
EMP_ID_REQUEST NUMBER(10),
EMP_ID_REVIEW NUMBER(10),
EMP_ID_DEVELOP NUMBER(10),
OBJ_ID NUMBER(10),
NAME_AR VARCHAR2(100 BYTE),
NAME_EN VARCHAR2(100 BYTE),
PURPOSE VARCHAR2(2000 BYTE),
TITLE VARCHAR2(200 BYTE),
IMAGE_PATH VARCHAR2(300 BYTE),
REQUEST_DATE DATE,
REVIEW_DATE DATE,
HELP_FILE_NAME VARCHAR2(200 BYTE),
FILE_NAME VARCHAR2(100 BYTE),
MODULE VARCHAR2(3 BYTE) DEFAULT 'HRS' NOT NULL,
DEVELOPED_DATE DATE,
ICON_NAME VARCHAR2(100 BYTE),
NODE_LVL NUMBER,
NOTES VARCHAR2(300 BYTE)
2- Building business component:
create a view object with this query
SELECT
ID, OBJECT_REASON, OBJ_SEQ,
OBJ_ID, NAME_AR, NAME_EN,
FILE_NAME, MODULE, ICON_NAME ,file_type
FROM SMM_V_SYS_OBJECTS
WHERE MODULE='HRS'
AND FILE_TYPE='F'
AND OBJECT_REASON='ADF'
AND OBJ_ID IS NOT NULL
AND OBJ_ID = :p_object_id
ORDER BY OBJ_SEQ
The parameter "p_object_id" refers to the tree node which represents the system Id
3- create jsf template
create a page template that contains af:foreach and one commandNavaigationItem as follow
<?xml version='1.0' encoding='UTF-8'?>
<af:pageTemplateDef xmlns:af="http://xmlns.oracle.com/adf/faces/rich" var="attrs" definition="private"
xmlns:afc="http://xmlns.oracle.com/adf/faces/rich/component" xmlns:f="http://java.sun.com/jsf/core">
<af:panelStretchLayout id="pt_psl1" dimensionsFrom="parent">
<f:facet name="center">
<af:facetRef facetName="content"/>
</f:facet>
<f:facet name="top">
<af:navigationPane id="pan">
<af:forEach items="#{bindings.MenuFormsVo.children}" var="row" varStatus="rowStatus" begin="0">
<af:commandNavigationItem text="#{row.NameAr}" actionListener="#baseTemplateBean.setSelectedTab}"
selected="#{row.Id eq bindings.Id.inputValue}"
action="#{baseTemplateBean.openFragment}"
>
<af:setPropertyListener from="#{row.FileName}" to="#{baseTemplateBean.commandAction}"
type="action"/>
<f:attribute name="recId" value="#{row.keyPath}"/>
</af:commandNavigationItem>
</af:forEach>
</af:navigationPane>
</f:facet>
</af:panelStretchLayout>
<af:xmlContent>
<afc:component>
<afc:description>for main frgments</afc:description>
<afc:display-name>mainFragmentTemplate</afc:display-name>
<afc:facet>
<afc:facet-name>content</afc:facet-name>
</afc:facet>
</afc:component>
</af:xmlContent>
</af:pageTemplateDef>
when you click on the tree node on the right side, the page fragment on the left side is populated dynamically at runtime with a navigationPane.The commandNavigationItems are rendered at runtime. To do this , follow theses steps:
1- you must have a database table that stores the data of the commandNavigationItem like this
CREATE TABLE SMM_SYS_OBJECTS
(
ID NUMBER(10) NOT NULL,
OBJECT_REASON VARCHAR2(3 BYTE) DEFAULT 'REP' NOT NULL,
OBJ_SEQ NUMBER(3),
FILE_TYPE VARCHAR2(1 BYTE) DEFAULT 'M' NOT NULL,
EMP_ID_REQUEST NUMBER(10),
EMP_ID_REVIEW NUMBER(10),
EMP_ID_DEVELOP NUMBER(10),
OBJ_ID NUMBER(10),
NAME_AR VARCHAR2(100 BYTE),
NAME_EN VARCHAR2(100 BYTE),
PURPOSE VARCHAR2(2000 BYTE),
TITLE VARCHAR2(200 BYTE),
IMAGE_PATH VARCHAR2(300 BYTE),
REQUEST_DATE DATE,
REVIEW_DATE DATE,
HELP_FILE_NAME VARCHAR2(200 BYTE),
FILE_NAME VARCHAR2(100 BYTE),
MODULE VARCHAR2(3 BYTE) DEFAULT 'HRS' NOT NULL,
DEVELOPED_DATE DATE,
ICON_NAME VARCHAR2(100 BYTE),
NODE_LVL NUMBER,
NOTES VARCHAR2(300 BYTE)
2- Building business component:
create a view object with this query
SELECT
ID, OBJECT_REASON, OBJ_SEQ,
OBJ_ID, NAME_AR, NAME_EN,
FILE_NAME, MODULE, ICON_NAME ,file_type
FROM SMM_V_SYS_OBJECTS
WHERE MODULE='HRS'
AND FILE_TYPE='F'
AND OBJECT_REASON='ADF'
AND OBJ_ID IS NOT NULL
AND OBJ_ID = :p_object_id
ORDER BY OBJ_SEQ
The parameter "p_object_id" refers to the tree node which represents the system Id
3- create jsf template
create a page template that contains af:foreach and one commandNavaigationItem as follow
<?xml version='1.0' encoding='UTF-8'?>
<af:pageTemplateDef xmlns:af="http://xmlns.oracle.com/adf/faces/rich" var="attrs" definition="private"
xmlns:afc="http://xmlns.oracle.com/adf/faces/rich/component" xmlns:f="http://java.sun.com/jsf/core">
<af:panelStretchLayout id="pt_psl1" dimensionsFrom="parent">
<f:facet name="center">
<af:facetRef facetName="content"/>
</f:facet>
<f:facet name="top">
<af:navigationPane id="pan">
<af:forEach items="#{bindings.MenuFormsVo.children}" var="row" varStatus="rowStatus" begin="0">
<af:commandNavigationItem text="#{row.NameAr}" actionListener="#baseTemplateBean.setSelectedTab}"
selected="#{row.Id eq bindings.Id.inputValue}"
action="#{baseTemplateBean.openFragment}"
>
<af:setPropertyListener from="#{row.FileName}" to="#{baseTemplateBean.commandAction}"
type="action"/>
<f:attribute name="recId" value="#{row.keyPath}"/>
</af:commandNavigationItem>
</af:forEach>
</af:navigationPane>
</f:facet>
</af:panelStretchLayout>
<af:xmlContent>
<afc:component>
<afc:description>for main frgments</afc:description>
<afc:display-name>mainFragmentTemplate</afc:display-name>
<afc:facet>
<afc:facet-name>content</afc:facet-name>
</afc:facet>
</afc:component>
</af:xmlContent>
</af:pageTemplateDef>
in the page definition of the template , add the iterators and a tree binding as follow
<?xml version="1.0" encoding="UTF-8" ?>
<pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel" version="12.1.2.66.68" id="mainFragmentTemplatePageDef"
Package="templates">
<parameters/>
<executables>
<variableIterator id="variables"/>
<iterator id="MenuFormsVoIterator" Binds="MenuFormsVo" DataControl="HrmsAppModuleDataControl" RangeSize="25"/>
</executables>
<bindings>
<attributeValues IterBinding="MenuFormsVoIterator" id="Id">
<AttrNames>
<Item Value="Id"/>
</AttrNames>
</attributeValues>
<attributeValues IterBinding="MenuFormsVoIterator" id="NameAr">
<AttrNames>
<Item Value="NameAr"/>
</AttrNames>
</attributeValues>
<attributeValues IterBinding="MenuFormsVoIterator" id="NameEn">
<AttrNames>
<Item Value="NameEn"/>
</AttrNames>
</attributeValues>
<tree IterBinding="MenuFormsVoIterator" id="MenuFormsVo">
<nodeDefinition DefName="org.dhaman.hrms.main.model.view.MenuFormsVo" Name="MenuFormsVo0">
<AttrNames>
<Item Value="Id"/>
<Item Value="FileName"/>
<Item Value="FileType"/>
<Item Value="IconName"/>
<Item Value="Module"/>
<Item Value="NameAr"/>
<Item Value="NameEn"/>
<Item Value="ObjectReason"/>
<Item Value="ObjId"/>
<Item Value="ObjSeq"/>
</AttrNames>
</nodeDefinition>
</tree>
</bindings>
</pageDefinition>
4- create a managed bean like this for the page template
public class BaseTemplateBeanClass {
private RichNavigationPane navapane;
private ADFLogger logger;
private String currrentMenuId;
private RichCommandNavigationItem commandNavItem;
private String commandAction;
private String taskFlowId = "Task flow id required by developer";
private String selectedCommandId;;
private RichPanelFormLayout myForm;
public void setSelectedTab(ActionEvent ae) {
List key = (List)ae.getComponent().getAttributes().get("recId");
JUCtrlHierBinding treeBinding = this.getTreeBinding();
JUCtrlHierNodeBinding currentNode = treeBinding.findNodeByKeyPath(key);
makeCurrent(currentNode);
}
private void makeCurrent(JUCtrlHierNodeBinding node) {
Row rw = node.getRow();
Key key = rw.getKey();
JUCtrlHierBinding treeBinding = this.getTreeBinding();
DCIteratorBinding iterator = treeBinding.getDCIteratorBinding();
iterator.setCurrentRowWithKey(key.toStringFormat(true));
}
private JUCtrlHierBinding getTreeBinding() {
BindingContext bctx = BindingContext.getCurrent();
BindingContainer bindings = bctx.getCurrentBindingsEntry();
JUCtrlHierBinding treeBinding = (JUCtrlHierBinding) bindings.get("MenuFormsVo");
return treeBinding;
}
}
Comments