2011年3月7日 星期一

自訂Alfresco屬性值限制

Alfresco本身提供四種基本屬性值限制(Constraint),分別是:
  1. REGEX: 字串樣式規則
  2. LIST:列表式值
  3. MINMAX:區間值
  4. LENGTH:字串長度
為便於重用Constraint,我們利用以上四種基本型別製作一個比較大顆(Coarse Grain)的Constraint。例如:上篇文章提到的費用請款自訂屬性集(Custom Aspect)裡的『歸屬部門』與『費用分類』可以LIST方式呈現,『總金額』可以MINMAX方式限制,以避免使用者的錯誤輸入。

請開啟自訂資料模型檔customModel.xml(路徑請參考here),在</namespaces>結束標籤下方加入以下文字:
<constraints>
   <constraint name="custom:DepartmentList" type="LIST">
     <parameter name="allowedValues">
        <list>
            <value>研發部</value>
            <value>業務部</value>
            <value>管理部</value>
       </list>
     </parameter>
   </constraint>
   <constraint name="custom:ExpTypeList" type="LIST">
     <parameter name="allowedValues">
        <list>
            <value>交通費</value>
            <value>誤餐費</value>
            <value>住宿費</value>
            <value>油電費</value>
            <value>影印費</value>
            <value>文具用品</value>
            <value>書報雜誌</value>
            <value>設備維修</value>
       </list>
     </parameter>
   </constraint>
   <constraint name="custom:ExpAmtMax" type="MINMAX">
     <parameter name="minValue">
        <value>10</value>
     </parameter>
     <parameter name="maxValue">
        <value>10000</value>
     </parameter>
   </constraint>
</constraints>
再將以上三個Constraint加入自訂屬性的定義內,請在同一個檔案(customModel.xml)內將游標移到aspects >> aspect >> properties 內的 custom:Department 屬性標籤,在</property>結束標籤前加上:
<constraints>
   <constraint ref="custom:DepartmentList"/>
</constraints>
在custom:ExpenseType屬性標籤的</property>結束標籤前加上:
<constraints>
   <constraint ref="custom:ExpTypeList"/>
</constraints>
在custom:TotAmount屬性標籤的</property>結束標籤前加上:
<constraints>
   <constraint ref="custom:ExpAmtMax"/>
</constraints>
以上設定就完成了。因為Cutom Model只有在Alfresco啟動時讀入,修改後需重新啟動Server才可生效。
嘗試修改已存入的費用檔案看看,總金額故意填入100000
按OK確定後,螢幕出現的輸入限制對話框

沒有留言: