cancel
Showing results for 
Search instead for 
Did you mean: 

Primitive Collection type attribute

Former Member
0 Kudos

How can a String[] attribute be implemented in items.xml.

Please give an example.

Accepted Solutions (1)

Accepted Solutions (1)

andyfletcher
Active Contributor
0 Kudos

You can't do a String array but you can get a Collection<String> by using the StringCollection type.

e.g.

 <attribute type="StringCollection" qualifier="myListOfStrings">
     <persistence type="property"/>
 </attribute>

will generate a model with methods signatures public Collection<String> getMyListOfStrings() and public void setMyListOfStrings(Collection<String> value)

They are actually backed by a UnmodifiableRandomAccessList as can be seen by running the following Groovy

 flexibleSearchService.search('select {pk} from {cmssite}').result[0].urlPatterns.class.name

(the urlPatterns attribute of CMSSite is a StringCollection)

but this does mean you need to create a new collection to modify them

e.g.

 List<String> listOfStrings = new ArrayList<>(myCustomType.getMyListOfStrings());
 listOfString.add("test data");
 myCustomType.setMyListOfStrings(listOfStrings);
 modelService.save(myCustomType);

Be aware that it is stored in the database as a serialized string so it isn't easily searchable using flexiblesearch. You can kind of work around it using where {myListOfString} like '%searchString%' but performance is going to suffer. If you need to search them you'd be better off using a regular relationship to a type.

Former Member
0 Kudos

Thanks

former_member620692
Active Contributor
0 Kudos

What a nice explanation! I just wanted to add that I have posted a solution at https://answers.sap.com/questions/12750906/how-to-retrieve-the-data-and-see-for-blob-object-c.html?c... and also at https://answers.sap.com/questions/12770772/how-to-verify-whether-a-string-exists-in-string-co.html?c... to retrieve the full StringCollection or to find the presence of a String in it.

Answers (0)