About

This site deals with technicalities of web development and content management systems. I also try to touch upon content strategy, ECM, DMS, and other related fields. 

I try to publish something new every two weeks alternating between topics.

Navigation
Social
« Congratulations Mr & Mrs Hicks | Main | I'm on YouTube »
Monday
Oct102011

Dynamic data lists in CQ5

The author-mode edit dialogues in CQ5 are great especially if you populate them with your own options for dropdown lists. If you have a nice handy JSON data source which is conveniently organised into key/value pairs, you can use this in your CQ5 author dialogues to provide the values for dropdowns, combo boxes, and lists of radio buttons and checkboxes. It's very easy if you data that looks something like this:

{"mydata":[
{"id":"1","label":"one"},
{"id":"2","label":"two"},
{"id":"3","label":"three"},
{"id":"4","label":"four"},
{"id":"5","label":"five"},
{"id":"6","label":"six"}
]}

when you create the edit control in the dialog, set these properties and it will load the remote data and use it

optionsProvider = URL
optionsRoot = 'mydata'
optionsLabelField = 'label'
optionsValueField = 'id'
xtype = 'selection'
type = 'select' [or radio, checkbox, combo]

along with all the usual properties, and it should show your data labels in the drop down, and store the values in the repository. There are some caveats as noted in the documentation, mostly that the data needs to be HTML entity encoded or escaped otherwise < and > do bad things. It's also not clear how to unselect it and have no option in the saved data, so you might need to design the dialog with this in mind. Finally, the defaults for the checkboxes are somewhat questionable.

PrintView Printer Friendly Version

EmailEmail Article to Friend