gpt4 book ai didi

java - ActionListener - 如何调用它们并向它们发送值

转载 作者:行者123 更新时间:2023-12-01 19:33:56 25 4
gpt4 key购买 nike

我有一个按钮,我为其定义了一个 Action 监听器:

<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类:

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

}
}

我想要的是将参数(文档的 UNID)发送到类,定位文档,使用数据构建 java 对象并将结果显示在屏幕上,例如在对话框中。

问题是:我该怎么做?

定义 Action 监听器时,我只能定义类型。不是参数...

最佳答案

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>

关于java - ActionListener - 如何调用它们并向它们发送值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58505061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com