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表单,大大的提高了表单的灵活性。