如何在Lotus Forms外创建一个Html的提交按钮将表单提交到服务器

Lotus Forms本身支持提交按钮将自己提交到服务器端。但在实际应用中往往需要在提交前进行一些操作,这些操作难以通过表单本身的提交按钮来触发,因此可以采用Html页面上的提交按钮来实现。

 

实现思路是通过Lotus Forms提供的js api实现,但由于3.5.1的js api未将表单提交api发布出来,因此需要曲线救国。

 

我的思路是通过js api修改表单中的一个隐藏域,表单中设计一个类型为done的action,这个action的active属性根据隐藏域的值进行变化,一旦隐藏域发生了变化action自动触发将表单提交到url上。代码如下:

<script src="./js/LF_XFDL.js"></script>
<script src="./js/LF_FormNodeP.js"></script>
<script type="text/javascript">

var objectID = "Main"; 

function submit() {
  
    try {
    
    var value = "<sumbittrigger>true</sumbittrigger>";
      // set the value of the HIDDENYEAR field, which activates the compute
      ibmForms[objectID].updateXFormsInstance(null,"instance('INSTANCE')/sumbittrigger",
          null, value, XFDL.UFL_XFORMS_UPDATE_REPLACE);     
      
    } catch (error) {
      alert("Could not set up custom form\n\n" + error);
    }
}
 
</script>

<input name="submit" type="button" onClick="submit();" value="submit" /> 

 

 

表单设计

 

<field sid="FIELD1">
         <xforms:textarea ref="instance('INSTANCE')/sumbittrigger">
            <xforms:label></xforms:label>
         </xforms:textarea>
         <itemlocation>
            <x>233</x>
            <y>110</y>
         </itemlocation>
         <scrollhoriz>wordwrap</scrollhoriz>
         <scrollvert>fixed</scrollvert>
      </field>

<action sid="ACTION1">
          <delay>
         <type>once</type>
         <interval>0</interval>
      </delay>
         
                  <type>done</type>
         <url>http://forms.cdb.com:8080/FormsJSTC/FormView</url>
         <active compute="toggle(PAGE1.FIELD1.value) == '1' ? 'on' : 'off'">off</active>
         
      </action>

 

 

FormView重载IBMWorkplaceFormsServerServlet,代码如下:

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		try {
			this.useHTML(resp, true);
			
			String filePath = this.getServletContext().getRealPath("/Forms") + "/jsform.xfdl";
			FileInputStream fis = new FileInputStream(filePath);
			XFDL xfdl = IFSSingleton.getXFDL();
			FormNodeP form = xfdl.readForm(fis, XFDL.UFL_SERVER_SPEED_FLAGS);
			fis.close();		

			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			form.writeForm(bos, null, 0);
			
			bos.writeTo(resp.getOutputStream());				
			bos.close();

			this.setFormName(resp, "Main");
			resp.setContentType("application/vnd.xfdl");
		} catch (UWIException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		resp.setContentType("text/html");
		resp.getWriter().write("Success");
	}


 通过以上这种方式,Lotus Forms可以专注于自己擅长的表单设计,而把与工作流交互的工作交给了html表单,大大的提高了表单的灵活性。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值