具有多个表单和数据源的 Xpage 创建空文档
Xpage with multiple forms and data sources create empty documents
- 我有两个简单的表单(Form1 和 Form2)。他们只有一个领域
每个(字段 1)。我创建了两个自定义控件。它们是相同的,除了
cc1 的数据源定义为 Form1,cc2 的数据源为
表格 2.
- 每个自定义控件都有一个输入框绑定到的field1字段
相应的数据源和一个提交按钮。我创建了一个
Xpage 并将两个自定义控件拉入页面。
- 如果我在 Xpage 中预览并填写输入框
浏览器,当我点击任何提交按钮时,两个文件
将根据domino数据库中的两个表单创建。
- 我尝试使用部分 refresh/execution 和许多其他东西。
无论我做什么,我总是得到两个表格的空文档。
XPage:
<xp:div styleClass="container" style="margin-top:20px">
<xp:div styleClass="row">
<xc:cc1></xc:cc1>
<xc:cc2></xc:cc2>
</xp:div>
</xp:div>
自定义控件 1
<xp:this.data>
<xp:dominoDocument var="form1" formName="form1"></xp:dominoDocument>
</xp:this.data>
<xp:div id="formDiv1" styleClass="col-sm-4">
<xp:form>
<xp:label value="Form 1" styleClass="h3"></xp:label>
<xp:div styleClass="form-group">
<xp:label value="Field 1" styleClass="control-label"></xp:label>
<xp:inputText value="#{form1.field1}"></xp:inputText>
</xp:div>
<xp:button value="Submit Form1" id="form1Btn">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" immediate="false" save="true" refreshId="formDiv1"
execMode="partial" execId="formDiv1">
</xp:eventHandler>
</xp:button>
</xp:form>
自定义控件 2
<xp:this.data>
<xp:dominoDocument var="form2" formName="form2"></xp:dominoDocument>
</xp:this.data>
<xp:div id="formDiv1" styleClass="col-sm-4">
<xp:form>
<xp:label value="Form 2" styleClass="h3"></xp:label>
<xp:div styleClass="form-group">
<xp:label value="Field 1" styleClass="control-label"></xp:label>
<xp:inputText value="#{form2.field1}"></xp:inputText>
</xp:div>
<xp:button value="Submit Form2" id="form2Btn">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" immediate="false" save="true" refreshId="formDiv1"
execMode="partial" execId="formDiv1">
</xp:eventHandler>
</xp:button>
</xp:form>
普通提交按钮获取 属性 save="true"
并保存 所有 数据源。
如果您只想保存一个数据源然后使用简单的操作Save Document
和select数据源:
另外设置属性save="false"
。那么您的按钮代码将如下所示:
<xp:button
id="form1Btn"
value="Submit Form1">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete"
immediate="false"
save="false">
<xp:this.action>
<xp:saveDocument
var="form1"></xp:saveDocument>
</xp:this.action>
</xp:eventHandler>
</xp:button>
下面是使用 Knut 建议的代码:
Xpage
<xp:div styleClass="container" style="margin-top:20px">
<xp:div styleClass="row">
<xc:cc1></xc:cc1>
<xc:cc2></xc:cc2>
</xp:div>
</xp:div>
cc1
<xp:panel id="formDiv1" styleClass="col-sm-4">
<xp:this.data>
<xp:dominoDocument var="form1" formName="form1"></xp:dominoDocument>
</xp:this.data>
<xp:label value="Form 1" styleClass="h3"></xp:label>
<xp:div styleClass="form-group">
<xp:label value="Field 1" styleClass="control-label"></xp:label>
<xp:inputText id="field1" value="#{form1.field1}"></xp:inputText>
</xp:div>
<xp:button value="Save" id="form1Btn">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" immediate="false" save="false" execMode="partial"
execId="formDiv1" refreshId="formDiv1">
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument var="form1"></xp:saveDocument>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:
var panel = getComponent("formDiv1");
var ds = new com.ibm.xsp.model.domino.DominoDocumentData();
ds.setComponent(panel);
ds.setVar("form1");
ds.setFormName("form1");
panel.getData().clear();
panel.addData(ds);}]]></xp:this.script>
</xp:executeScript>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:panel>
cc2
<xp:panel id="formDiv2" styleClass="col-sm-4 ">
<xp:this.data>
<xp:dominoDocument var="form2" formName="form2"></xp:dominoDocument>
</xp:this.data>
<xp:label value="Form 2" styleClass="h3"></xp:label>
<xp:div styleClass="form-group">
<xp:label value="Field 1" styleClass="control-label"></xp:label>
<xp:inputText id="field1" value="#{form2.field1}">
</xp:inputText>
</xp:div>
<xp:button value="Submit Form2" id="form2Btn">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" immediate="false" save="false" execMode="partial"
execId="formDiv2" refreshId="formDiv2">
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument var="form2"></xp:saveDocument>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:
var panel = getComponent("formDiv2");
var ds = new com.ibm.xsp.model.domino.DominoDocumentData();
ds.setComponent(panel);
ds.setVar("form2");
ds.setFormName("form2");
panel.getData().clear();
panel.addData(ds);}]]></xp:this.script>
</xp:executeScript>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:panel>
Paul Wither 关于对数据源使用 requestScope 范围的建议使代码变得相当简单:
XPage
<xp:div styleClass="container" style="margin-top:20px">
<xp:div styleClass="row">
<xc:cc1></xc:cc1>
<xc:cc2></xc:cc2>
</xp:div>
自定义控件 1
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.data>
<xp:dominoDocument var="form1" formName="form1" scope="request"></xp:dominoDocument>
</xp:this.data>
<xp:div id="formDiv1" styleClass="col-sm-4">
<xp:label value="Form 1" styleClass="h3"></xp:label>
<xp:div styleClass="form-group">
<xp:label value="Field 1" styleClass="control-label"></xp:label>
<xp:inputText id="field1" value="#{form1.field1}"></xp:inputText>
</xp:div>
<xp:button value="Save" id="form1Btn">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" immediate="false" save="false" execMode="partial" execId="formDiv1"
refreshId="formDiv1">
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument var="form1"></xp:saveDocument>
</xp:actionGroup>
</xp:this.action>
<xp:this.onComplete><![CDATA[x$("#{id:field1}").val("");]]></xp:this.onComplete>
</xp:eventHandler>
</xp:button>
</xp:div>
</xp:view>
自定义控件 2
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.data>
<xp:dominoDocument var="form2" formName="form2" scope="request"></xp:dominoDocument>
</xp:this.data>
<xp:div id="formDiv2" styleClass="col-sm-4 ">
<xp:label value="Form 2" styleClass="h3"></xp:label>
<xp:div styleClass="form-group">
<xp:label value="Field 1" styleClass="control-label"></xp:label>
<xp:inputText id="field1" value="#{form2.field1}">
</xp:inputText>
</xp:div>
<xp:button value="Submit Form2" id="form2Btn">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" immediate="false" save="false" execMode="partial"
execId="formDiv2" refreshId="formDiv2">
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument var="form2"></xp:saveDocument>
</xp:actionGroup>
</xp:this.action>
<xp:this.onComplete><![CDATA[x$("#{id:field1}").val("");]]></xp:this.onComplete>
</xp:eventHandler>
</xp:button>
</xp:div>
</xp:view>
- 我有两个简单的表单(Form1 和 Form2)。他们只有一个领域 每个(字段 1)。我创建了两个自定义控件。它们是相同的,除了 cc1 的数据源定义为 Form1,cc2 的数据源为 表格 2.
- 每个自定义控件都有一个输入框绑定到的field1字段
相应的数据源和一个提交按钮。我创建了一个
Xpage 并将两个自定义控件拉入页面。 - 如果我在 Xpage 中预览并填写输入框 浏览器,当我点击任何提交按钮时,两个文件 将根据domino数据库中的两个表单创建。
- 我尝试使用部分 refresh/execution 和许多其他东西。 无论我做什么,我总是得到两个表格的空文档。
XPage:
<xp:div styleClass="container" style="margin-top:20px">
<xp:div styleClass="row">
<xc:cc1></xc:cc1>
<xc:cc2></xc:cc2>
</xp:div>
</xp:div>
自定义控件 1
<xp:this.data>
<xp:dominoDocument var="form1" formName="form1"></xp:dominoDocument>
</xp:this.data>
<xp:div id="formDiv1" styleClass="col-sm-4">
<xp:form>
<xp:label value="Form 1" styleClass="h3"></xp:label>
<xp:div styleClass="form-group">
<xp:label value="Field 1" styleClass="control-label"></xp:label>
<xp:inputText value="#{form1.field1}"></xp:inputText>
</xp:div>
<xp:button value="Submit Form1" id="form1Btn">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" immediate="false" save="true" refreshId="formDiv1"
execMode="partial" execId="formDiv1">
</xp:eventHandler>
</xp:button>
</xp:form>
自定义控件 2
<xp:this.data>
<xp:dominoDocument var="form2" formName="form2"></xp:dominoDocument>
</xp:this.data>
<xp:div id="formDiv1" styleClass="col-sm-4">
<xp:form>
<xp:label value="Form 2" styleClass="h3"></xp:label>
<xp:div styleClass="form-group">
<xp:label value="Field 1" styleClass="control-label"></xp:label>
<xp:inputText value="#{form2.field1}"></xp:inputText>
</xp:div>
<xp:button value="Submit Form2" id="form2Btn">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" immediate="false" save="true" refreshId="formDiv1"
execMode="partial" execId="formDiv1">
</xp:eventHandler>
</xp:button>
</xp:form>
普通提交按钮获取 属性 save="true"
并保存 所有 数据源。
如果您只想保存一个数据源然后使用简单的操作Save Document
和select数据源:
另外设置属性save="false"
。那么您的按钮代码将如下所示:
<xp:button
id="form1Btn"
value="Submit Form1">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete"
immediate="false"
save="false">
<xp:this.action>
<xp:saveDocument
var="form1"></xp:saveDocument>
</xp:this.action>
</xp:eventHandler>
</xp:button>
下面是使用 Knut 建议的代码:
Xpage
<xp:div styleClass="container" style="margin-top:20px">
<xp:div styleClass="row">
<xc:cc1></xc:cc1>
<xc:cc2></xc:cc2>
</xp:div>
</xp:div>
cc1
<xp:panel id="formDiv1" styleClass="col-sm-4">
<xp:this.data>
<xp:dominoDocument var="form1" formName="form1"></xp:dominoDocument>
</xp:this.data>
<xp:label value="Form 1" styleClass="h3"></xp:label>
<xp:div styleClass="form-group">
<xp:label value="Field 1" styleClass="control-label"></xp:label>
<xp:inputText id="field1" value="#{form1.field1}"></xp:inputText>
</xp:div>
<xp:button value="Save" id="form1Btn">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" immediate="false" save="false" execMode="partial"
execId="formDiv1" refreshId="formDiv1">
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument var="form1"></xp:saveDocument>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:
var panel = getComponent("formDiv1");
var ds = new com.ibm.xsp.model.domino.DominoDocumentData();
ds.setComponent(panel);
ds.setVar("form1");
ds.setFormName("form1");
panel.getData().clear();
panel.addData(ds);}]]></xp:this.script>
</xp:executeScript>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:panel>
cc2
<xp:panel id="formDiv2" styleClass="col-sm-4 ">
<xp:this.data>
<xp:dominoDocument var="form2" formName="form2"></xp:dominoDocument>
</xp:this.data>
<xp:label value="Form 2" styleClass="h3"></xp:label>
<xp:div styleClass="form-group">
<xp:label value="Field 1" styleClass="control-label"></xp:label>
<xp:inputText id="field1" value="#{form2.field1}">
</xp:inputText>
</xp:div>
<xp:button value="Submit Form2" id="form2Btn">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" immediate="false" save="false" execMode="partial"
execId="formDiv2" refreshId="formDiv2">
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument var="form2"></xp:saveDocument>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:
var panel = getComponent("formDiv2");
var ds = new com.ibm.xsp.model.domino.DominoDocumentData();
ds.setComponent(panel);
ds.setVar("form2");
ds.setFormName("form2");
panel.getData().clear();
panel.addData(ds);}]]></xp:this.script>
</xp:executeScript>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:panel>
Paul Wither 关于对数据源使用 requestScope 范围的建议使代码变得相当简单:
XPage
<xp:div styleClass="container" style="margin-top:20px">
<xp:div styleClass="row">
<xc:cc1></xc:cc1>
<xc:cc2></xc:cc2>
</xp:div>
自定义控件 1
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.data>
<xp:dominoDocument var="form1" formName="form1" scope="request"></xp:dominoDocument>
</xp:this.data>
<xp:div id="formDiv1" styleClass="col-sm-4">
<xp:label value="Form 1" styleClass="h3"></xp:label>
<xp:div styleClass="form-group">
<xp:label value="Field 1" styleClass="control-label"></xp:label>
<xp:inputText id="field1" value="#{form1.field1}"></xp:inputText>
</xp:div>
<xp:button value="Save" id="form1Btn">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" immediate="false" save="false" execMode="partial" execId="formDiv1"
refreshId="formDiv1">
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument var="form1"></xp:saveDocument>
</xp:actionGroup>
</xp:this.action>
<xp:this.onComplete><![CDATA[x$("#{id:field1}").val("");]]></xp:this.onComplete>
</xp:eventHandler>
</xp:button>
</xp:div>
</xp:view>
自定义控件 2
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.data>
<xp:dominoDocument var="form2" formName="form2" scope="request"></xp:dominoDocument>
</xp:this.data>
<xp:div id="formDiv2" styleClass="col-sm-4 ">
<xp:label value="Form 2" styleClass="h3"></xp:label>
<xp:div styleClass="form-group">
<xp:label value="Field 1" styleClass="control-label"></xp:label>
<xp:inputText id="field1" value="#{form2.field1}">
</xp:inputText>
</xp:div>
<xp:button value="Submit Form2" id="form2Btn">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" immediate="false" save="false" execMode="partial"
execId="formDiv2" refreshId="formDiv2">
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument var="form2"></xp:saveDocument>
</xp:actionGroup>
</xp:this.action>
<xp:this.onComplete><![CDATA[x$("#{id:field1}").val("");]]></xp:this.onComplete>
</xp:eventHandler>
</xp:button>
</xp:div>
</xp:view>