相关blog
http://www.oracle.com/technetwork/issue-archive/2011/11-may/o31adf-352561.html
http://oracle.sys-con.com/node/1497222/mobile
http://biemond.blogspot.com/2009/01/passing-adf-events-between-task-flow.html
http://one-size-doesnt-fit-all.blogspot.com/2010/08/jdev-contextual-events-payload-payload.html
http://jobinesh.blogspot.com/2010/11/triggering-navigation-from-contextual.html
关于Region间通讯(一个Region订阅另一个Region发布的事件),由于订阅的Region通过配置界面不可能选择到发布Region的事件,因此需要手工的修改订阅页面的PageDef.xml来订阅事件,代码如下,注意红字部分:
<?xml version=”1.0” encoding=”UTF-8” ?>
<pageDefinition xmlns=”http://xmlns.oracle.com/adfm/uimodel“
version=”11.1.1.60.13” id=”eventTargetPageDef”
Package=”dj.demo.contextualevent.view.fragments”>
<parameters/>
<executables>
<variableIterator id=”variables”/>
</executables>
<bindings>
<methodAction id=”eventHandler” InstanceName=”TestPage.dataProvider”
DataControl=”TestPage” RequiresUpdateModel=”true”
Action=”invokeMethod” MethodName=”eventHandler”
IsViewObjectMethod=”false”>
<NamedData NDName=”event” NDType=”java.lang.Object”/>
</methodAction>
</bindings>
<eventMap xmlns=”http://xmlns.oracle.com/adfm/contextualEvent">
<event name=”buttonPressed”><!–订阅名称–>
<producer region=”*”><!–订阅来源–>
<consumer region=”” handler=”eventHandler” handleCondition=””>
<parameters>
<parameter name=”event” value=”#{payLoad}”/>
</parameters>
</consumer>
</producer>
</event>
</eventMap>
<events xmlns=”http://xmlns.oracle.com/adfm/contextualEvent"/>
</pageDefinition>
关于将Backing Bean 方法暴露为DataControl,如果使用自动的方法,将生成一堆东西。
解决方法为生成后删除或手工配置,相关配置文件及示例(Bean Class为TestPage,注意红字部分):
DataControls.dcx
<?xml version=”1.0” encoding=”UTF-8” ?>
<DataControlConfigs xmlns=”http://xmlns.oracle.com/adfm/configuration“
version=”11.1.1.60.13” id=”DataControls”
Package=”dj.demo.contextualevent.view“>
<AdapterDataControl id=”TestPage”
FactoryClass=”oracle.adf.model.adapter.DataControlFactoryImpl”
ImplDef=”oracle.adf.model.adapter.bean.BeanDefinition”
SupportsTransactions=”false” SupportsSortCollection=”true”
SupportsResetState=”false” SupportsRangesize=”false”
SupportsFindMode=”false” SupportsUpdates=”true”
Definition=”dj.demo.contextualevent.TestPage“
BeanClass=”dj.demo.contextualevent.TestPage“
xmlns=”http://xmlns.oracle.com/adfm/datacontrol">
<CreatableTypes>
<TypeInfo FullName=”dj.demo.contextualevent.TestPage“/>
</CreatableTypes>
<Source>
<bean-definition BeanClass=”dj.demo.contextualevent.TestPage“
xmlns=”http://xmlns.oracle.com/adfm/adapter/bean"/>
</Source>
</AdapterDataControl>
</DataControlConfigs>
TestPage.xml
<?xml version=”1.0” encoding=”UTF-8” ?>
<JavaBean xmlns=”http://xmlns.oracle.com/adfm/beanmodel“ version=”11.1.1.60.13”
id=”TestPage” Package=”dj.demo.contextualevent”
BeanClass=”dj.demo.contextualevent.TestPage” isJavaBased=”true”>
<MethodAccessor IsCollection=”false” Type=”void” id=”eventHandler”
ReturnNodeName=”Return”>
<ParameterInfo id=”event” Type=”java.lang.Object” isStructured=”false”/>
</MethodAccessor>
<ConstructorMethod IsCollection=”true” Type=”dj.demo.contextualevent.TestPage”
BeanClass=”dj.demo.contextualevent.TestPage”
id=”TestPage”/>
</JavaBean>
DataBindings.cpx
<?xml version=”1.0” encoding=”UTF-8” ?>
<Application xmlns=”http://xmlns.oracle.com/adfm/application“
version=”11.1.1.60.13” id=”DataBindings” SeparateXMLFiles=”false”
Package=”dj.demo.contextualevent.view” ClientType=”Generic”>
<definitionFactories>
<factory nameSpace=”http://xmlns.oracle.com/adf/controller/binding“
className=”oracle.adf.controller.internal.binding.TaskFlowBindingDefFactoryImpl”/>
<dtfactory className=”oracle.adf.controller.internal.dtrt.binding.BindingDTObjectFactory”/>
</definitionFactories>
<pageMap>
<page path=”/TestPage.jspx”
usageId=”dj_demo_contextualevent_view_TestPagePageDef”/>
<page path=”/dj/demo/contextualevent/view/fragments/eventSource.jsff”
usageId=”dj_demo_contextualevent_view_eventSourcePageDef”/>
<page path=”/dj/demo/contextualevent/view/fragments/eventTarget.jsff”
usageId=”dj_demo_contextualevent_view_eventTargetPageDef”/>
</pageMap>
<pageDefinitionUsages>
<page id=”dj_demo_contextualevent_view_TestPagePageDef”
path=”dj.demo.contextualevent.view.pageDefs.TestPagePageDef”/>
<page id=”dj_demo_contextualevent_view_eventSourcePageDef”
path=”dj.demo.contextualevent.view.fragments.eventSourcePageDef”/>
<page id=”dj_demo_contextualevent_vieweventTargetPageDef”
path=”dj.demo.contextualevent.view.fragments.eventTargetPageDef”/>
</pageDefinitionUsages>
<dataControlUsages>
<dc id=”TestPage” path=”dj.demo.contextualevent.view.TestPage”/>
</dataControlUsages>
</Application>
如果DataControls.dcx是新建立的话,还需修改adfm.xml
adfm.xml
<?xml version=”1.0” encoding=”UTF-8” ?>
<MetadataDirectory xmlns=”http://xmlns.oracle.com/adfm/metainf“
version=”11.1.1.0.0”>
<DataBindingRegistry path=”dj/demo/contextualevent/view/DataBindings.cpx”/>
<DataControlRegistry path=”dj/demo/contextualevent/view/DataControls.dcx”/>
</MetadataDirectory>
关于Action和Listener的Type,参见这两份Java Doc
http://myfaces.apache.org/trinidad/trinidad-api/apidocs/org/apache/myfaces/trinidad/event/package-tree.html
http://download.oracle.com/javaee/6/api/javax/faces/event/package-tree.html
Listener和Event的使用,需要修改发布Event的page的pageDef.xml,示例如下,注意红字部分
pageDef.xml_
<?xml version=”1.0” encoding=”UTF-8” ?>
<pageDefinition xmlns=”http://xmlns.oracle.com/adfm/uimodel“
version=”11.1.1.60.13” id=”eventSourcePageDef”
Package=”dj.demo.contextualevent.view.fragments”>
<parameters/>
<executables>
<variableIterator id=”variables”/>
</executables>
<bindings>
<eventBinding id=”eventBinding”
Listener=”javax.faces.event.ActionListener”>
<events xmlns=”http://xmlns.oracle.com/adfm/contextualEvent">
<event name=”buttonPressed”
customPayLoad=”#{pageFlowScope.ctePayload}“
eventType=”Action Event”/>
</events>
</eventBinding>
</bindings>
<events xmlns=”http://xmlns.oracle.com/adfm/contextualEvent">
<event name=”buttonPressed” customPayLoad=”#{pageFlowScope.ctePayload}“
eventType=”Action Event”/>
</events>
</pageDefinition>
在Backing Bean 代码中raise event,注意Listener的转换类型与Event的类型需要与上述配置匹配
package view;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import oracle.adf.model.BindingContext;
import oracle.binding.BindingContainer;
import oracle.jbo.uicli.binding.JUEventBinding;
public class PublisherBean {
public PublisherBean() {
}
public void doAction(ActionEvent actionEvent) {
BindingContainer bindingContainer = BindingContext.getCurrent().getCurrentBindingsEntry();
JUEventBinding eventBinding = (JUEventBinding)bindingContainer.get("publisherEvent");
ActionListener actionListener = (ActionListener)eventBinding.getListener();
actionListener.processAction(actionEvent);
}
}