2015-02-10 55 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);        
} 

希望有所帮助。