Reputation: 1947
I am trying to implement a method that replaces all values inside a Hashmap with all the values inside a document.
The idea behind that is that I loop through all items
that I get from Document.getItems()
and simply use the Item.getType()
method so I can decide what type I use for which field.
Something like that:
private void replace(SomeClass model, Document document) {
Map<String, Object> objectsMap = model.getObjectsMap();
Vector<Item> items = document.getItems();
for(Item item : items) {
if(item.getType() == Item.TEXT) {
model.add(item.getName(), item.getValueString()); // model.add(...) is basically a Map.put(String key, Object value);
} else if(item.getType() == Item.AUTHORS) {
// ...
} else if(/*...*/) {
// ...
}
}
}
Now my problem is that I cannot distinguish between a Text
and a TextList
because getType()
returns 1280 for both.
Has anyone tried something like that already or maybe can give me a hint of what approach might be a workaround?
EDIT
Regarding the idea from one of the comments, to use a TextList
when item.getValues().size() > 1
and Text
otherwise:
As mentioned in the comment the problem is, that I want to be able to use the field later as well.
For example:
If I have a TextList
field with one item in the document, and I would use the approach described above, I would put a String inside the Map
for this field.
If I want to add more Items to this field (which should be a Vector
since originally it was a TextList
) I wouldn't be able to - at least not in a straight forward way.
Upvotes: 0
Views: 1212
Reputation: 20384
NotesItems always return A Vector for values. There is no distinction between text and textList. However what you could do: get the form object and check the field properties. If allow multi value is ticked, then you can presume it was intended as textList rather than text. That should sort your conversion decision. You also could flag items with more than one value that don’t have allow multi value set in the field - code would have done that
Upvotes: 1
Reputation: 1399
You could check the size of item.getValues() - which returns a Vector . If the size of the vector is > 0 it is a textilst.
Upvotes: 0