ActionListener - 如何通过向它们发送值来调用它们

ActionListener - how to call them with sending values to them

我有一个按钮,我为其定义了一个动作侦听器:

<xp:button value="#{matter.attachment_upload}"
        id="btnSaveFile" styleClass="btnSaveFile" disabled="true"
        title="#{matter.gen_Attachment_Help}">
        <xp:this.attrs>
            <xp:attr name="data-placement"
                value="bottom">
            </xp:attr>
            <xp:attr name="data-toggle"
                value="tooltip">
            </xp:attr>
        </xp:this.attrs>
        <i class="fa fa-upload" aria-hidden="true" />
        &#160;
        <xp:eventHandler event="onclick"
            submit="true" refreshMode="complete" disableValidators="true">
            <xp:this.action><![CDATA[#{javascript:attachmentBean.save(compositeData.ref,compositeData.key)}]]></xp:this.action>
            <xp:this.onComplete><![CDATA[//pnlFiles
XSP.partialRefreshGet('#{id:pnlFiles}');]]></xp:this.onComplete>
            <xp:this.actionListeners>
    <xp:actionListener
        type="se.acme.projectx.app.HelloWorld">
    </xp:actionListener>
</xp:this.actionListeners></xp:eventHandler>
</xp:button>

连接到此 java class:

package se.acme.projectx.app;

import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;

public class HelloWorld implements ActionListener {

    private String SomeVariable;
    private String AnotherVariable;

    // Class Constructor...
    public HelloWorld() {
        System.out.println("HelloWOrld");
    }

    // Property getters/setters
    public String getSomeVariable() {
        return SomeVariable;
    }

    public String getAnotherVariable() {
        return AnotherVariable;
    }

    public void setSomeVariable(String someVariable) {
        SomeVariable = someVariable;
    }

    public void setAnotherVariable(String anotherVariable) {
        AnotherVariable = anotherVariable;
    }

    @Override
    public void processAction(ActionEvent arg0) throws AbortProcessingException {
        // TODO Auto-generated method stub

    }
}

我想要的是向 class 发送一个参数(文档的 UNID),找到一个文档,用数据构建一个 java 对象并在屏幕上显示结果例如在对话框中。

问题是:我该怎么做?

定义actionlistener时只能定义类型。不是参数...

ActionEvent 将数据传输到您的 ActionListener。您必须像这样获取事件处理程序:

package ch.hasselba.xpages;

import java.util.List;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import com.ibm.xsp.complex.Parameter;
import com.ibm.xsp.component.xp.XspEventHandler;

public class MyActionListener implements javax.faces.event.ActionListener {

    public void processAction(ActionEvent event)
            throws AbortProcessingException {
        XspEventHandler eventHandler = (XspEventHandler) event.getSource();
        List<Parameter> params = eventHandler.getParameters();
        for (Parameter p : params) {
            System.out.println(p.getName() + " -> " + p.getValue());
        }
    }
}

要设置参数,请将参数添加到您的事件处理程序:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

    <xp:inputText
        id="inputTextMyData"
        value="#{requestScope.myData}">
    </xp:inputText>

    <xp:button
        value="do It!"
            id="buttonAction">
        <xp:eventHandler
            event="onclick"
            submit="true"
            refreshMode="norefresh">

            <xp:this.parameters>
                <xp:parameter name="param">
                    <xp:this.value><![CDATA[#{javascript:requestScope.get('myData')}]]></xp:this.value>
                </xp:parameter>
            </xp:this.parameters>

            <xp:this.actionListeners>
                    <xp:actionListener type="ch.hasselba.xpages.MyActionListener" />
                </xp:this.actionListeners>
            </xp:eventHandler>

    </xp:button>