如何基于规则对Web应用程序工作流实施约束
我们的 Web 应用程序存在以下问题。 有一个在应用程序上创建订单的工作流程:
输入有关客户的信息(一个 Web 表单)
输入有关设备的信息(另一个 Web 表单)表单)
以及每个表单上的一些限制,以便进入下一步:
客户具有一系列属性(名字、姓氏、街道、电话号码)需要指定
当客户希望通过短信通知时,需要指定有效的手机号码引入
- 设备的有效手机号码
(对于检索到的支付类型(卡/现金/支票),有一定的条件)客户为了创建而接受的金额 设备的订单
目前这些约束是直接实现的在应用程序的源代码中,这使得应用程序更难维护(某些规则从应用程序的一个版本更改为下一个版本)。
创建订单时从代码中外部化这些检查的好方法是什么?
像 Drools 这样的规则引擎可能是一个很好的解决方案,但我想为站点管理员提供通过可视化编辑器定义验证规则的可能性。 有人可以推荐我一个针对这种情况已经存在的解决方案吗?
We have the following problem in our web application.
There is a workflow for creating an order on the application :
entering informations about the customer (one web form)
entering informations about the device (another web form)
and some constraints on each form in order to advance to the next step :
the customer has a series of attributes (first name, last name, street, telephone number) which need to be specified
when the customer wants to be notified by sms then a valid mobile phone number needs to be introduced
for the device (for a which a payment type (Card/Cash/Cheque) retrieved dy there is a certain amount of money to be accepted by the customer in order to create the order
Currently these constraints are implemented directly in the source code of the application, and this is making the application harder to maintain (some of the rules change from a version of the application to the next).
What would be a good approach to externalize these checks from the code when creating the order?
A rule-engine like Drools could be a good solution, but I'd like to give the possibility to the administrator of the site, via a visual editor to define the validation rules.
Can anybody recommend me a solution which exists already for this situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建一个单独的流程来验证用户的信息。我们创建了一个 servlet,所有请求都通过它(如果您愿意,您可以使用 JSP)。当请求到来时,我们可以获取请求参数并将它们以及用户填写的表单类型传递给验证类。验证类将执行所需的验证,然后传回 true 或 false 以及任何失败的字段的名称。
当 servlet 启动时,它将访问数据库或 XML 文件并检索每个表单所需的字段并将其存储在其缓存中。数据库或 XML 文件中的字段与 HTML 表单中的字段具有相同的名称。如果您想添加/删除所需的字段,您只需在 HTML 表单中添加/删除该字段,并从数据库或 XML 文件中添加/删除该字段。不需要更改代码。由于验证数据存储在缓存中,因此在服务器启动时数据库或 XML 文件只会被读取一次。如果性能不是问题,您可以每次都从数据库或 XML 文件中读取。
您还可以通过将正则表达式与表单字段名称一起存储来验证数据是否有效(例如姓氏具有有效字符)。这样,您只需更改数据库或 XML 文件中的表达式即可更改字段的验证方式。没有代码更改,没有重大的重新测试。
You could create a separate process for validating information from the user. we have created a servlet that all request come through (You could use JSP's if you wanted). When a request comes in we can get the request parameters and pass them to the validation classes along with what type of form the user filled out. The validation classes would do the required validation and then pass back true or false along with the names of any fields that failed.
When the servlet starts up it would go to a database or XML file and retrieve the required fields for each form and store it in it's cache. The fields in the database or XML file would have the same name as the fields in the HTML form. If you wanted to add/remove a field that is required you would just need to add/remove the field in the HTML form and add/remove the field from the database or XML file. No code changes would be needed. Since the validation data is stored in cache the database or XML file would only be read once when the server is started. If performance is not an issue you could read from the database or XML file every time.
You could also validate that the data was valid (ex. last name has valid characters) by also storing regular expressions along with the form field names. This way you could change how a field is validated by just changing the expression in the database or XML file. No code changes no major retesting.
在某种程度上 spring-webflow 可以帮助你。否则有各种工作流程/bpm类型的解决方案可用(我曾在Savvion BPM上工作过一次),那么我认为jboss drools就在那里。
to some extent spring-webflow can help you. otherwise there are various workflow/bpm kind of solutions available (i had worked on Savvion BPM once), then I think jboss drools is there.