
在此項目中,打開“創建JSF聲明性組件”向導:

新的聲明性組件smartLovDef應該至少具有三個屬性:用于標簽的一些字符串,用于輸入文本的屬性綁定和用于組合框值列表的LOV綁定:

該向導創建元數據文件declarativecomp-metadata.xml和smartLovDef.jspx文件,我們可以在其中放置組件的內容:

smartLovDef.jspx的源代碼如下所示:
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"xmlns:f="http://java.sun.com/jsf/core"xmlns:h="http://java.sun.com/jsf/html"xmlns:af="http://xmlns.oracle.com/adf/faces/rich"><jsp:directive.page contentType="text/html;charset=UTF-8"/><af:componentDef var="attrs" componentVar="component"><af:panelLabelAndMessage label="#{attrs.label}" id="plam1"><af:panelGroupLayout id="pgl1" layout="horizontal"><af:inputText value="#{attrs.attrBinding.inputValue}"required="#{attrs.attrBinding.hints.mandatory}"columns="#{attrs.attrBinding.hints.displayWidth}"id="deptid" partialTriggers="departmentNameId"autoSubmit="true" simple="true"/><af:inputComboboxListOfValues id="departmentNameId"popupTitle="Search and Select: #{attrs.lovBinding.hints.label}"value="#{attrs.lovBinding.inputValue}"model="#{attrs.lovBinding.listOfValuesModel}"columns="#{attrs.lovBinding.hints.displayWidth}"shortDesc="#{attrs.lovBinding.hints.tooltip}"partialTriggers="deptid"simple="true"></af:inputComboboxListOfValues></af:panelGroupLayout></af:panelLabelAndMessage><af:xmlContent><component xmlns="http://xmlns.oracle.com/adf/faces/rich/component"><display-name>smartLovDef</display-name><attribute><attribute-name>label</attribute-name><attribute-class>java.lang.String</attribute-class><required>true</required></attribute><attribute><attribute-name>attrBinding</attribute-name><attribute-class>java.lang.Object</attribute-class><required>true</required></attribute><attribute><attribute-name>lovBinding</attribute-name><attribute-class>java.lang.Object</attribute-class><required>true</required></attribute><component-extension><component-tag-namespace>cscomponent</component-tag-namespace><component-taglib-uri>/componentLib</component-taglib-uri></component-extension></component></af:xmlContent></af:componentDef>
</jsp:root>
下一步是將組件部署到ADF庫中。 我們必須為CSComponents項目添加新的部署配置文件:


然后將項目部署到庫中:


下一步是在資源面板中定義到CSComponents項目的部署路徑的文件系統連接:


之后,我們必須選擇要使用新組件的項目(在我的情況下為ViewConroller),然后向其中添加CSComponents.jar庫:

現在,我們可以在頁面中使用smartLovDef組件并將其從組件面板中拖動:

在我們的jspx頁面中,源代碼將如下所示:
<cscompLib:smartLovDef label="#{bindings.DepartmentId.label}"attrBinding="#{bindings.DepartmentId}" lovBinding="#{bindings.DepartmentName}"id="sld1"/>
參考: JCG合作伙伴提供的 ADF聲明性組件示例 ? ADF實踐博客上的Eugene Fedorenko。
翻譯自: https://www.javacodegeeks.com/2012/03/adf-declarative-component-example.html