on 12-01-2016 11:50 AM
How can a String[] attribute be implemented in items.xml.
Please give an example.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
User | Count |
---|---|
5 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.