OFBiz进阶--OFBiz标签之[*Services.xml]-mililang介绍与分析(三)[判断<if/check-*>]
OFBiz进阶--OFBiz标签之
[*Services.xml]-mililang介绍与分析(三)
Mililang标签:
<if/check-*>****, 判断操作(Conditional (If) Operations)
***标签规则: [***simple-methods.xsd] 新版本还有 [simple-methods-v2.xsd]
<if>
<condition><if-compare operator="less" value="" field="" format="" type="String"></if-compare></condition>
<then><return/></then>
<else-if>
<condition><if-compare operator="less" value="" field="" format="" type="String"></if-compare></condition>
<then><return/></then>
</else-if>
<else><return/></else>
</if>
<!-- 上述标签组合类似 java:if..else..; if 符合条件 then, elseif 符合条件 then, else; -->
<if-compare operator="less" value="" field="" format="" type="String"></if-compare>
<!-- field变量的值与 value内容比较 -->
<if-compare field="containsEmptyFields" operator="equals" value="true"/>
<if-compare-field operator="less" field="" format="" to-field="" type="String"></if-compare-field>
<!-- field变量的值与 to-field变量的值比较 -->
<if-compare-field field="newEntity.amount" to-field="originalAmount" operator="not-equals" type="BigDecimal">
<log level="warning" message="In createFinAccountTrans had to round the amount from [${originalAmount}] to [${newEntity.amount}]"></log>
</if-compare-field>
<if-empty field=""></if-empty>
<!-- 如果 field变量空 -->
<if-empty field="currentOrganizationPartyId"></if-empty>
<if-has-permission permission="" action=""></if-has-permission>
<!-- 如果当前登录用户有 permission指定模块的 action指定的权限 -->
<if-has-permission permission="PAY_INFO" action="_CREATE"/>
<if-instance-of class="" field=""></if-instance-of>
<!-- 如果 field变量是 class指定的java类 的类型 -->
<if-instance-of field="answers["${currentFieldName}"]" class="java.nio.ByteBuffer">
<make-value entity-name="Content" value-field="content"/>
</if-instance-of>
<if-not-empty field=""></if-not-empty>
<!-- 如果 field变量不为空 -->
<if-not-empty field="entityValue"></if-not-empty>
<if-regexp field="" expr=""></if-regexp>
<!-- 如果 field变量 能匹配 expr 正则表达式 -->
<if-regexp field="parameters.partyTaxId" expr="${taxAuthority.taxIdFormatPattern}"/>
<if-regexp expr="text.*" field="persistIn.drMimeTypeId" />
<if-validate-method field="" method="" class="org.ofbiz.base.util.UtilValidate"></if-validate-method>
<!-- 将 field变量传入 class指定的类中的 method指定的方法中校验 -->
<if-validate-method field="${answerFieldName}" method="isDate"/>
<check-id field="" error-list-name="error_list"><fail-message message=""/></check-id>
<!-- 获取指定变量中的错误消息: field错误消息 -->
<check-id field="parameters.fixedAssetId"/>
<check-permission permission="NOTE" action="_${parameters.mainAction}" error-list-name="error_list">
<!-- 检查权限: permission权限名; action具体权限值; -->
<!-- 使用check-permission前提条件是当前service 环境中必须存在用户的登陆信息,即能获取到userLogin .
service 的调用场景有很多,controller.xml中,screen中,simple method 中,bsh文件中,ftl 文件中,java 文件中,groovy文件中等,
其中前三项系统会自动将userLogin,locale 等信息自动封装到service context 中去,所以不需要我们手段传值,
所以我们在其他环境中调用service的时候就需要对需要的隐性参数进行传值,比如fail-property中会用到locale,
check-permission会用到userLogin 等,调用举例如下:
dispatcher.runSync("TestServiceOnSimple",UtilMisc.toMap("param3","TestServiceOnJava","userLogin",userLogin,"locale",locale)); //java文件中
-->
<accept-userlogin-party party-id-env-name="partyId"/>
<!-- 当前登录用户若无权限, 但操作的数据与当前登录人相关, 则当前登录人也有操作权限, 即校验为true, 如允许用户看到自己的订单,或更新自己的联系人信息。 -->
<alt-permission permission="" action=""/>
<!-- 给当前登录用户分配的备用权限, 若<check-permission>权限校验为false, 继续校验此标签配置权限, 若为true, 则权限校验通过; <alt-permission>可以多个 -->
<!-- check-permission 和 alt-permission 两者的关系是or的关系,即只要两者有一个满足权限要求即可。 -->
<fail-message message=""/>
<!-- <fail-property resource="" property=""/> -->
</check-permission>
<check-errors/>
<!-- <check-permission permission="ACCOUNTING" action="_UPDATE"/> -->
<assert error-list-name="error_list" title="">
<!-- 断言:在方法或循环中放置断言, 当断言检查失败时,中断方法的执行,向错误消息列表添加错误消息; error-list-name错误信息列表变量名; title断言的消息 -->
<and><if-regexp field="" expr=""></if-regexp></and>
<not><if-regexp field="" expr=""></if-regexp></not>
<or><if-regexp field="" expr=""></if-regexp></or>
<xor><if-regexp field="" expr=""></if-regexp></xor>
<!-- and/not/or/xor: 并且/非/或者/异或(用于判断数据是否符合条件, 上句是变量是否匹配指定的正则表达式); field变量名; expr正则表达式; -->
</assert>
<while>
<condition><if-compare operator="less" value="" field=""></if-compare></condition>
<then></then>
</while>
<!-- while循环: 符合condition中的条件, 则执行 then 中的过程 -->
<while>
<condition>
<and>
<not><if-empty field="currentOrganizationPartyId"></if-empty></not>
<if-compare field="containsEmptyFields" operator="equals" value="true"/>
</and>
</condition>
<then>
<clear-field field="parentPartyRelationship"/>
<clear-field field="entityKey"/>
<clear-field field="entityValue"/>
</then>
</while>
==================================关于本文===================================
作者: mf1389004071
.....上海_香飘飘
博客: http://ofbizer.iteye.com/
邮箱: mf1389004071@163.com
有此标记, 均为原创, 禁止盗用, 转载请注明来源
技术无上限, 能力有上限, 欢迎参与交流讨论和提出建议
本文永久地址: http://ofbizer.iteye.com/blog/2040203