2013年5月15日星期三

ADF_218:ADF Mobile 11.1.2.4 Samples 介绍(4):JavaDemo

开发运行环境:JDeveloper 11.1.2.4 + Android SDK r21.1

JavaDemo演示了如何在UI与Java beans之间建立联系,并且还演示了如何在Java中调用EL bindings。

知识点:

1. 如何从一个Feature到另一个Feature
(1)页面代码
<amx:commandButton id="commandLink1" text="Invoke Handler"
                       actionListener="#{pageFlowScope.DemoBean.ActionHandler}"/>
(2)Java代码
    public void ActionHandler(ActionEvent actionEvent) {
        AdfmfContainerUtilities.gotoFeature("Success");
    }
说明:
(1)"Success"是另个Feature的id值,并且设置为隐藏。
(2)Features是否可见,是设置在adfmf-application.xml中的:


2. 如何使用ValueChangeListener
(1)页面代码
<amx:selectBooleanSwitch id="selectBooleanSwitch1" value="#{pageFlowScope.DemoBean.navBarStatus}"
                           label="Navigation Bar" offLabel="Off" onLabel="On"
                           valueChangeListener="#{pageFlowScope.DemoBean.ValueHandler}"/>
                           
(2)Java代码
    public void ValueHandler(ValueChangeEvent valueChangeEvent) {
        String showNav = (String)valueChangeEvent.getNewValue().toString();
        if(showNav.equals("true") ) {
            AdfmfContainerUtilities.showNavigationBar();
        }
        else {
            AdfmfContainerUtilities.hideNavigationBar();
        }
    }

3. 如何在Java中使用EL
(1)页面代码
<amx:commandButton text="Value #{pageFlowScope.button1}"
id="commandButton1" actionListener="#{pageFlowScope.DemoBean.ValueExprHandler}"/>

<amx:commandButton actionListener="#{pageFlowScope.DemoBean.MethodExprHandler}" text="Method"
id="commandButton2"/>
(2)Java代码
    public void ValueExprHandler(ActionEvent actionEvent) {
        ValueExpression ve = AdfmfJavaUtilities.getValueExpression("#{pageFlowScope.button1}", String.class);
        String button1 = (String)ve.getValue(AdfmfJavaUtilities.getAdfELContext());
        button1 += "+";
        ve.setValue(AdfmfJavaUtilities.getAdfELContext(), button1);
    }

    public void MethodExprHandler(ActionEvent actionEvent) {
        MethodExpression me = AdfmfJavaUtilities.getMethodExpression("#{bindings.DoMyMethod.execute}", Object.class, new Class[] {}); 
        me.invoke(AdfmfJavaUtilities.getAdfELContext(), new Object[] {});
    }

4. 如何在Java中调用Data Control 暴露的方法
(1)页面代码

<amx:commandButton actionListener="#{bindings.DoMyMethod.execute}" text="Do MyMethod"
                           id="commandButton1"/>

(2)Java代码

    public void MethodExprHandler(ActionEvent actionEvent) {
        MethodExpression me = AdfmfJavaUtilities.getMethodExpression("#{bindings.DoMyMethod.execute}", Object.class, new Class[] {});
        me.invoke(AdfmfJavaUtilities.getAdfELContext(), new Object[] {});
    }


5. 完整的Java Bean 代码:

package mobile;

import javax.el.MethodExpression;
import javax.el.ValueExpression;

import oracle.adfmf.amx.event.ActionEvent;
import oracle.adfmf.amx.event.ValueChangeEvent;
import oracle.adfmf.framework.api.AdfmfContainerUtilities;
import oracle.adfmf.framework.api.AdfmfJavaUtilities;

public class Javademobean {
    public Javademobean() {
    }
    
    private Boolean navBarStatus = Boolean.TRUE;

    public void ActionHandler(ActionEvent actionEvent) {
        AdfmfContainerUtilities.gotoFeature("Success");
    }

    public void ValueHandler(ValueChangeEvent valueChangeEvent) {
        String showNav = (String)valueChangeEvent.getNewValue().toString();
        if(showNav.equals("true") ) {
            AdfmfContainerUtilities.showNavigationBar();
        }
        else {
            AdfmfContainerUtilities.hideNavigationBar();
        }
    }

    public void setNavBarStatus(Boolean navBarStatus) {
        this.navBarStatus = navBarStatus;
    }

    public Boolean getNavBarStatus() {
        return navBarStatus;
    }
    
    public void DoMyMethod() {
        AdfmfContainerUtilities.gotoFeature("Success");
    }

    public void ValueExprHandler(ActionEvent actionEvent) {
        ValueExpression ve = AdfmfJavaUtilities.getValueExpression("#{pageFlowScope.button1}", String.class);
        String button1 = (String)ve.getValue(AdfmfJavaUtilities.getAdfELContext());
        button1 += "+";
        ve.setValue(AdfmfJavaUtilities.getAdfELContext(), button1);
    }

    public void MethodExprHandler(ActionEvent actionEvent) {
        MethodExpression me = AdfmfJavaUtilities.getMethodExpression("#{bindings.DoMyMethod.execute}", Object.class, new Class[] {}); 
        me.invoke(AdfmfJavaUtilities.getAdfELContext(), new Object[] {});
    }
}

没有评论: