In this lesson, you will learn how to check whether or not a property value satisfies a particular rule. For this purpose, the DemoTask.Status property and the MarkCompleted Action will be used. This action should not be executed if the current task status is "NotStarted". Thus, the rule will be checked when executing the MarkCompleted Action.

在本课中,您将学习如何检查属性值是否满足特定规则。为此,将使用 DemoTask.Status 属性和标记完成操作。如果当前任务状态为"未启动",则不应执行此操作。因此,在执行"标记完成操作"时将检查规则。

Note
Before proceeding, take a moment to review the following lessons.
  • Implement Property Value Validation in Code (XPO/EF)
  • Place an Action in a Different Location

注意

在继续之前,请花点时间复习以下课程。

  • 在代码中实现属性值验证 (XPO/EF)
  • 将操作放置在其他位置

The validation functionality is provided by the Validation Module that was added in the Implement Property Value Validation in Code (XPO) lesson. When this module is added to the MySolution.Module project, the Validation node is available in the Application Model. This node defines the validation Contexts and Rules used in your application. You can use the Model Editor to add Rules and specify Contexts.

验证功能由在代码 (XPO) 课程中添加的验证模块提供。当此模块添加到 MySolution.模块项目时,验证节点在应用程序模型中可用。此节点定义应用程序中使用的验证上下文和规则。您可以使用模型编辑器添加规则并指定上下文。

  • Invoke the Model Editor for the MySolution.Module project. Navigate to the Validation | Rules node. It already contains child nodes that define the rules to be checked. For example, it may contain the "RuleRequiredField for Position.Title" rule that was implemented in the Implement Property Value Validation in Code (XPO) lesson. To add a new rule that checks specific criteria, right-click the Rules node and select Add... | RuleCriteria.

  • 调用 MySolution.模块项目的模型编辑器。导航到验证 |规则节点。它已包含定义要检查的规则的子节点。例如,它可能包含在代码 (XPO) 课程中实现属性值验证中的"位置.Title.Title"规则。要添加检查特定条件的新规则,请右键单击"规则"节点并选择"添加..." |规则标准。

    Note 注意
    The descriptions of all available rule types are available in the Validation Rules topic.

    所有可用规则类型的说明在验证规则主题中可用。

  • For the newly created node, set the TargetType to "MySolution.Module.BusinessObjects.DemoTask", and set the Criteria property to "Status != 'NotStarted'". Set the ID property to "TaskIsNotStarted", TargetContextIDs to "MarkCompleted" and CustomMessageTemplate to "Cannot set the task as completed because it has not started".
  • 对于新创建的节点,将目标类型设置为"MySolution.Module.业务对象.演示任务",并将"条件"属性设置为"状态!= "未启动"。将 ID 属性设置为"TaskIsNot 已启动",将目标上下文ID 设置为"标记为已完成",将自定义消息模板设置为"无法将任务设置为已完成,因为它尚未启动"。

Note 注意
The Criteria property value must be specified using the Criteria Language Syntax. To simplify this task, you can invoke the Filter Builder dialog by clicking the ellipsis button () to the right of the Criteria value. Within this dialog, you can visually design a criteria expression.

必须使用"条件语言语法"指定"条件"属性值。要简化此任务,可以通过单击条件值右侧的省略号按钮 (EllipsisButton) 来调用"筛选器生成器"对话框。在此对话框中,您可以直观地设计条件表达式。

  • The TargetContextIDs property is set to "MarkCompleted". This means that the rule will be checked when executing the Action whose ValidationContexts property is set to "MarkCompleted". So, set the Mark Completed Action's ValidationContexts property (in the ActionDesign | Actions | Task.MarkCompleted node) to "MarkCompleted".

  • "目标上下文"属性设置为"标记已完成"。这意味着在执行其验证上下文属性设置为"标记完成"的操作时,将检查规则。因此,设置"标记已完成操作的验证上下文"属性(在操作设计 |操作 |任务.标记已完成节点)到"标记已完成"。

    Note 注意
    You can also use the Save or Delete contexts, which are available by default. Rules with these contexts are validated when an object is saved or deleted, respectively (see Validation Rules).

    您还可以使用默认可用的"保存或删除"上下文。分别保存或删除对象时,将验证具有这些上下文的规则(请参阅验证规则)。

  • Run the WinForms or ASP.NET application. Assign the "Not Started" value to the Status property of one of the existing DemoTask objects. Click the MarkCompleted button. The following Validation Error dialog will be displayed.

  • 运行 WinForms 或ASP.NET应用程序。将"未启动"值分配给现有演示任务对象之一的状态属性。单击"标记已完成"按钮。将显示以下验证错误对话框。

Note 注意
Generally, you can add the required rule to a class or property in code (see Implement Property Value Validation in Code (EF \ XPO)). The approach defined above is useful when the class sources are inaccessible.

通常,可以将所需的规则添加到代码中的类或属性(请参阅在代码中实现属性值验证 (EF = XPO)。)。当类源无法访问时,上面定义的方法非常有用。

You can see the changes made in this lesson in the Model Editor invoked for the Model.DesignedDiffs.xafml file located in the Main Demo | MainDemo.Module project. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

您可以在本课中为模型调用的模型编辑器中所做的更改。主演示模块项目。主演示应用程序安装在%PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

.

Implement Property Value Validation in the Application Model 在应用程序模型中实现属性值验证的更多相关文章

  1. Implement Property Value Validation in Code 在代码中实现属性值验证(XPO)

    This lesson explains how to set rules for business classes and their properties. These rules are val ...

  2. CompareValues标签对Model中的属性进行验证

    在Asp.Net MVC中实现CompareValues标签对Model中的属性进行验证   在Asp.Net MVC中可以用继承ValidationAttribute的方式,自定制实现Model两个 ...

  3. 在Asp.Net MVC中实现RequiredIf标签对Model中的属性进行验证

    在Asp.Net MVC中可以用继承ValidationAttribute的方式,自定制实现RequiredIf标签对Model中的属性进行验证 具体场景为:某一属性是否允许为null的验证,要根据另 ...

  4. <s:property="a" value=""/>取的<s:debug></s:debug>中的value stack中的属性值

    <s:property="a"  value=""/>取的<s:debug></s:debug>中的value stack中 ...

  5. 在Asp.Net MVC中实现CompareValues标签对Model中的属性进行验证

    在Asp.Net MVC中可以用继承ValidationAttribute的方式,自定制实现Model两个中两个属性值的比较验证 具体应用场景为:要对两个属性值的大小进行验证 代码如下所示: /// ...

  6. 在.Net MVC中自定义ValidationAttribute标签对Model中的属性做验证

    写一个继承与ValidationAttribute类的自定义的验证方法 MVC中传递数据时,大多数都会用Model承载数据,并且在传到控制器后,对Model进行一系列的验证. 我平时经常使用的判断方法 ...

  7. spring boot 读取配置文件(application.yml)中的属性值

    在spring boot中,简单几步,读取配置文件(application.yml)中各种不同类型的属性值: 1.引入依赖: <!-- 支持 @ConfigurationProperties 注 ...

  8. Convert Application Model Differences

    The eXpressApp Framework is based on the modules concept. As a rule, every module implements a certa ...

  9. java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'

    java.lang.IllegalStateException: Failed to load property source from location 'classpath:/applicatio ...

随机推荐

  1. JS 正则表达式^$详解,脱字符^与美元符$同时写表示什么意思?

     壹 ❀ 引 对于初学正则的同学来说,^$这两个看似简单的字符却在使用中总让匹配结果超出我们的预期,^什么时候表示行首什么时候表示反义?^ $两个一起写表示什么含义?今天我们就来详细聊聊这两个字符. ...

  2. Openresty快速安装

    1. 场景描述 软件老王帮同事初始化服务器,需要安装下Openresty,安装过好多次,但是命令还是记不住,这次又安装记录了下,直接按下面的命令next-next就行了,2-3分钟左右就ok了. 2. ...

  3. javascript对url进行编码和解码

    这里总结下JavaScript对URL进行编码和解码的三个方法. 为什么要对URL进行编码和解码 只有[0-9[a-Z] $ - _ . + ! * ' ( ) ,]以及某些保留字,才能不经过编码直接 ...

  4. conda docker镜像

    之前的python环境,使用ubuntu安装pip来安装python依赖,但是遇到缺少某些库的版本,比如一个项目需要用到faiss,pip只有最新的1.5.3版本,但是这个版本使用了较新的CPU指令, ...

  5. 松软科技Web课堂:JavaScript Break 和 Continue

    break 语句“跳出”循环. continue 语句“跳过”循环中的一个迭代. Break 语句 在本教程稍早的章节中,您已见到了 break 语句.它被用于“跳出” switch 语句. brea ...

  6. Zuul Swagger 整合

    疯狂创客圈 Java 高并发[ 亿级流量聊天室实战]实战系列 [博客园总入口 ] 架构师成长+面试必备之 高并发基础书籍 [Netty Zookeeper Redis 高并发实战 ] 前言 Crazy ...

  7. jQuery 源码解析(二十五) DOM操作模块 html和text方法的区别

    html和text都可以获取和修改DOM节点里的内容,方法如下: html(value)     ;获取匹配元素集合中的一个元素的innerHTML内容,或者设置每个元素的innerHTML内容,   ...

  8. mysql优化:覆盖索引(延迟关联)

    前言 上周新系统改版上线,上线第二天就出现了较多的线上慢sql查询,紧接着dba 给出了定位及解决方案,这里较多的是使用延迟关联去优化. 而我对于这个延迟关联也是第一次听说(o(╥﹏╥)o),所以今天 ...

  9. VUE+Element UI实现简单的表格行内编辑效果

    原理是通过Css控制绑定的输入控件与显示值,在选中行样式下对控件进行隐藏或显示 <!DOCTYPE html> <html> <head> <meta cha ...

  10. 【译】浅谈SOLID原则

    SOLID原则是一种编码的标准,为了避免不良设计,所有的软件开发人员都应该清楚这些原则.SOLID原则是由Robert C Martin推广并被广泛引用于面向对象编程中.正确使用这些规范将提升你的代码 ...