这就是我要做的。
为此,我有一个javascript函数,它可以很好地完成工作。
为了获得需要推送的值,我必须调用一个外部API,其中包含一些依赖于用户单击的参数。
我还在inputfield上设置了一个clientListener(valueChange)来调用我的javascript函数。
问题是,在用户调用调用API的my serverListener事件之后,当将值推送到inputfield内部时,不会调用clientListener。
我让字段可见以进行测试,我可以自己输入值,它可以工作,但是当bean在字段中推送值时,valueChange事件不会触发。
在bean检索到值后,如何获取要触发的事件,或者如何直接从bean调用javascript函数?
下面是我使用的代码示例
<af:resource type="javascript">
function pushValue(evt){
// push values to parent page
window.external.main.setFieldValue("fieldName", evt.getSource().getValue());
}
function callServerAPI(){
// call the serverListener
AdfCustomEvent.queue(it2, "callAPI", {somevalues}, true);
}
</af:resource>
<af:inputText label="My hidden field"
id="it2"
binding="#{pageFlowScope.MyAppBean.hiddenField}"
clientComponent="true">
<af:clientListener method="pushValue" type="valueChange"/>
<af:serverListener type="callAPI"
method="#{pageFlowScope.MyAppBean.callAPI}"/>
</af:inputText>
private RichInputText hiddenField;
public void callAPI(ClientEvent clientEvent) throws Exception {
String fieldValue = clientEvent.getParameters().get("somevalues").toString();
try {
// call the API and get the value needed in the hidden field
hiddenField.setValue(fetchValue(fieldValue));
} catch (Exception e) {
e.printStackTrace();
}
// refresh field
AdfFacesContext.getCurrentInstance().addPartialTarget(hiddenField);
}
提前感谢您的帮助!