2016-01-12 102 views
1

我有一個Alfresco工作流表單,其中有一個關聯字段,可以選擇多個用戶。字段UI定義是隱式的(模型定義了關聯)。Alfresco:如何爲cm:person關聯設置默認表單值

我想用當前登錄的用戶初始化該字段。

我試過使用表單過濾器,並使用FieldUtils.makeAssociationField()使用NodeRef作爲值,然後form.addField(),但這導致UnsupportedOperationException

雖然我使用相同的技術來無障礙地初始化屬性字段。

任何人都可以指出我的解決方法嗎?

private void initInitatorNodeRef(final Form form) 
    { 

     final String userName = AuthenticationUtil.getFullyAuthenticatedUser(); 

     if (userName != null) 
     { 
      final NodeRef person = personService.getPerson(userName); 

      if (person != null) 
      { 

       final AssociationDefinition definition = 
        serviceRegistry.getDictionaryService().getAssociation(MywfModel.ASSOC_AUTHORS); 

       final Field field = 
        FieldUtils.makeAssociationField(
         definition, person, null, serviceRegistry.getNamespaceService(), 
         serviceRegistry.getDictionaryService()); 

       form.addField(field); 
      } 
      else 
      { 
       throw new RuntimeException("Person not found."); 
      } 
     } 
     else 
     { 
      throw new RuntimeException("UserName not found."); 
     } 

    } 
+0

你可以爲你的異常附上完整的跟蹤以及你的露天版! –

+0

沒有堆棧跟蹤。 FormUIGet webscript似乎捕獲並掩蓋了異常。我目前正在測試Enterprise 5.0.2 –

+0

原因可能是您已經在模型中定義了該關聯,並且您正在添加一個具有相同名稱的新關聯? –

回答

0

一個workaround已經發現:

form.addData()是一些Map.put調用拋出一個異常,由於某種原因,在關聯的情況下,現場數據的地圖無法更新。我用內部方法form.getFormData().addFieldData()替換上面的行到強制覆蓋參數爲true並且它工作。該關聯現在以我的形式正確初始化。