2015-02-10 59 views
0

我創建了一個ActivityNode(條目)從ActivityNode刪除字段,我可以用不能修改/使用SBT

setFields(List<Field> newListField) 

fonction添加自定義字段。

但是

我無法修改這些字段。 (在這種情況下,我嘗試修改命名LIBENTITE字段的值)

FieldList list = myEntry.getTextFields(); 
List<Field> updatedList = new ArrayList<Field>(); 

//I add each old field in the new list, but I modify the field LIBENTITE 
for(Field myField : list){ 
    if(myField.getName().equals("LIBENTITE")){ 
     ((TextField)myField).setTextSummary("New value"); 
    } 
    updatedList.add(myField); 
} 

myEntry.setFields(updatedList); 
activityService.updateActivityNode(myEntry); 

此代碼應更換新的一個領域的老名單,但我不能看到自定義字段LIBENTITE任何變化IBM連接中的myEntry。

所以我試圖創建領域的一個新的列表,而不是修改我的領域,但增加一個新問題:

for(Field myField:list){ 
    if(!myField.getName().equals("LIBENTITE")){ 
     updatedList.add(myField); 
    } 
} 
Field newTextField = new TextField("New Value"); 
newTextField .setFieldName("LIBENTITE"); 
updatedList.add(newTextField); 

而這個代碼只是增加在myEntry的新領域。我看到的是其他自定義字段沒有更改,現在我在myEntry中有兩個名爲LIBENTITE的自定義字段,一個帶有舊值,另一個帶有新值。

所以我雖然也許如果我清除舊的字段列表,然後我添加新的,它會工作。 我試過兩個fonctions

myEntry.clearFieldsMap(); 

myEntry.remove("LIBENTITE"); 

但他們都不似乎工作,我仍然無法從myEntry使用SBT刪除自定義字段。

有什麼建議嗎?

+0

其中一位同事會回覆 – 2015-02-10 14:14:05

+0

嗨,我很高興看到您的評論。我仍然沒有找到解決方案。你有什麼消息嗎? – Chucky 2015-02-17 09:25:35

+0

目前,這個問題沒有解決辦法,TextFields是隻讀地圖。我們的問題記錄在https://github.com/OpenNTF/SocialSDK/issues/1657 – 2015-02-17 12:53:35

回答

0

只是讓後不留解答我寫的是最初的問題的評論答案:

「目前,還沒有解決這個問題,TextField的是隻讀的地圖我們有問題記錄在github.com/OpenNTF/SocialSDK/issues/1657「

0

我有兩個建議,因爲我有(或有)類似的問題:

如果你想在一個活動節點,以更新現有的文本字段,你必須調用node.setField(fld)在節點對象更新域。

代碼從我工作的應用程序代碼段,在那裏我更新包含(計算)文本字段開始時間:

ActivityNode node = activityService.getActivityNode(id); 
node.setTitle(formatTitle());  // add/update start and end time in title 
boolean startFound = false; 
    // ...       
FieldList textfields =node.getTextFields(); 
Iterator<Field> iterFields = textfields.iterator(); 
while (iterFields.hasNext()) { 
    TextField fld = (TextField) iterFields.next(); 
    if (fld.getName().equals(Constants.FIELDNAME_STARTTIME)) { 
     fld.setTextSummary(this.getStartTimeString());  // NOTE: .setFieldValue does *not* work 
     node.setField(fld);    // write updated field back. This seems to be the only way updating fields works 
     startFound=true; 
    } 
} 

如果沒有現場與這個名字,我創建一個新的(這是我使用startFound布爾變量的原因)。

我認爲node.setField(fld)應該做的伎倆。如果沒有,可能有辦法避開這個問題:

您可以訪問被解析的底層DOM對象。您可以使用它來調整DOM對象,最終將被寫回到Connections。 我不得不使用它,因爲在SBT SDK中似乎還有另一個令人討厭的錯誤:如果您在沒有值的文本字段中讀取並寫回,則會發生錯誤。看起來DOM對象會錯過一些必需的節點,所以您必須自己創建它們以避免錯誤。

一些代碼來證明這一點:

// .... 
} else if (null == fld.getTextSummary()) {  // a text field without any contents. Which is BAD! 

     // there is a bug in the SBT API: if we read a field which has no value 
     // and try to write the node back (even without touching the field) a NullPointerException 
     // will be thrown. It seems that there is no value node set for the field. We 
     // can't set a value with fld.setTextSummary(), the error will still be thrown. 
     // therefore we have to remove the field, and - optionally - we set a defined "empty" value 
     // to avoid the problem. 
    // node.remove(fld.getName());     // remove the field -- this does *not* work! At least not for empty fields 
     // so we have to do it the hard way: we delete the node of the field in the cached dom structure 
    String fieldName = fld.getName(); 
    DeferredElementNSImpl fldData = (DeferredElementNSImpl) fld.getDataHandler().getData(); 
    fldData.getParentNode().removeChild(fldData);  // remove the field from the cached dom structure, therefore delete it 
    // and create it again, but with a substitute value 
    Field newEmptyField = new TextField (Constants.FIELD_TEXTFIELD_EMPTY_VALUE); // create a field with a placeholder value 
    newEmptyField.setFieldName(fieldName); 
    node.setField(newEmptyField);        
} 

希望有所幫助。