如何使用Javascript调用ADF Action方法

本文介绍如何在用户按下Enter键时,通过JavaScript模拟触发ADF页面或页面片段中的按钮动作。提供了一个包含输入文本组件和命令按钮的页面片段示例,并展示了相应的JavaScript代码来实现这一功能。

How to execute an ADF button's action method using javascript

http://hazem-adf-tips.blogspot.com/2012/07/how-to-execute-adf-buttons-action.html


Suppose that we have  UI input components that, when the Enter key is pressed, will virtually press a button within a page or page fragment.
Let's assume a page fragment containing an input text component and a command button to press:

    <af:panelFormLayout id="pfl1">
    <f:facet name="footer">
    <af:commandButton text="save" id="cb1" action="#{testBean.buttonAction}"
      clientComponent="true"/>
    </f:facet>
    <af:inputText label="Label 1" id="it1" value="#{testBean.param1}" autoSubmit="true">
    <af:clientListener method="
executeButtonMethod" type="keyUp"/>
    </af:inputText>
    </af:panelFormLayout>


The command button is bound to a managed bean action method. By default, the action method is invoked when users press the command button. However, with the JavaScript shown next, this can be simulated and mapped to the Enter key press in the text field.

        <?xml version='1.0' encoding='UTF-8'?>
        <jsp:root xmlns:jsp="/JSP/Page" version="2.1"
        xmlns:af=/adf/faces/rich
        xmlns:f="/jsf/core">
        <af:resource type="javaScript">
        function  executeButtonMethod (event){
        if (event.getKeyCode() == AdfKeyStroke.ENTER_KEY) {
        var inputTextField = event.getSource();
        var button = inputTextField.findComponent('cb1');
        var partialSubmit = true;
        AdfActionEvent.queue(button, partialSubmit);           event.cancel();
                }
        }
        </af:resource>

For JavaScript to work, note the use of the af:clientListener on the input text field and the use of the clientComponent="true" configuration on the button.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值