Nav*_*een 2 xpages xpages-extlib
我正在尝试使用扩展库组件Remote Service(xe:jsonRpcService).我从这里和这里得到了一些提示.基本上我试图使用RPC保存文档.问题是文档被保存但它不保存XPage上的任何字段.以下是XPage示例代码:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
<xp:this.data>
<xp:dominoDocument var="document1" formName="Test"></xp:dominoDocument>
</xp:this.data>
<xe:jsonRpcService id="jsonRpcService1" serviceName="service">
<xe:this.methods>
<xe:remoteMethod name="saveDoc">
<xe:this.script><![CDATA[print(">> " + getComponent("inputText1").getValue());
document1.save();
return true;]]></xe:this.script>
</xe:remoteMethod>
</xe:this.methods>
</xe:jsonRpcService>
<xp:br></xp:br>
<xp:inputText id="inputText1" defaultValue="testValue" value="#{document1.testField}"></xp:inputText>
<xp:br></xp:br>
<xp:button value="Save" id="button1">
<xp:eventHandler event="onclick" submit="false">
<xp:this.script><![CDATA[var deferred = service.saveDoc();
deferred.addCallback(
function(result) {
alert(result);
}
);]]></xp:this.script>
</xp:eventHandler>
</xp:button>
</xp:view>
Run Code Online (Sandbox Code Playgroud)
我在这里做的是,我创建了Remote Service(service),我保存当前文档(document1).它保存文档但不保存值inputText1.此外,当我尝试打印inputText1它的值显示在控制台上,但它没有得到保存.
这是正确的方法吗?或者我在这里遗漏了一些东西.还有什么情况下使用xe:jsonRpcService是合理的?
Tim*_*ony 12
避免使用JSON-RPC进行此类操作至少有两个原因:
我的建议是将JSON-RPC视为"SOAP减去愚蠢".更礼貌地说,它在概念上与Web服务相同,但没有Web服务的复杂性.因此,这些类型的服务对于在当前页面的上下文中有用的数据操作是理想的,而不明确地与当前页面的状态相关联.
以下是一些JSON-RPC方法可能有用的操作示例:
这并不意味着您不能使用RPC进行写操作...但是对于需要完整,最新上下文(即当前页面上每个字段的当前值)才能正确运行的任何操作,标准事件处理程序几乎总是更好的方法.