Giancarlo F. Berner ha scritto:
Have you considered using the "Data" module?
Ciao Giancarlo!
This is a special message for you :-)
In my "working" ImagePicker (wich extends DialogSelect), the method
setOptions loads images definition from Data Module, as you (right)
suggested.
It works fine, but I miss something:
I retrieve images as you suggest in your wiki-guide (congratulation,
really clear!!)
But one by one! And knowing *before* their name..
I would like something like this:
A) look in DM under /website-layout/images/public-logos and discover how
many logos are there
B) iterate over logos and populate the select
No problem on B, but how can I retrieve for example a collection of
DataNodes? I've tried without success with a query... until QueryManager
code everything is working and I can see three images...
This is my temporary code... see logo1, logo2, logo3 oultrageous
programming code :-(
******************************************************
public void setOptions(Content configNode) {
// settings
String dataModulePath = "/site-layout/logos"; // The path/node within
the data module
String logoAltProperty = "alt-text";
String logoImgProperty = "image";
String logoNameProperty = "name";
// retrieve all logos
try {
//NodeData nd = =
MgnlContext.getHierarchyManager("data").getNodeData(dataModulePath);
log.warn("isNodeData? " +
MgnlContext.getHierarchyManager("data").isNodeData(dataModulePath));
Content logo1 =
MgnlContext.getHierarchyManager("data").getContent(dataModulePath +
"/logo-1");
Content logo2 =
MgnlContext.getHierarchyManager("data").getContent(dataModulePath +
"/logo-2");
Content logo3 =
MgnlContext.getHierarchyManager("data").getContent(dataModulePath +
"/logo-3");
String logo1Name = logo1.getNodeData(logoNameProperty).getString();
String logo2Name = logo2.getNodeData(logoNameProperty).getString();
String logo3Name = logo3.getNodeData(logoNameProperty).getString();
String logo1Uuid = logo1.getUUID();
String logo2Uuid = logo2.getUUID();
String logo3Uuid = logo3.getUUID();
List options = new ArrayList();
SelectOption option1 = new SelectOption("[1] " + logo1Name, logo1Uuid);
SelectOption option2 = new SelectOption("[2] " + logo2Name, logo2Uuid);
SelectOption option3 = new SelectOption("[3] " + logo3Name, logo3Uuid);
options.add(option1);
options.add(option2);
options.add(option3);
//this.setOptions(options);
QueryManager qm =
MgnlContext.getHierarchyManager("data").getQueryManager();
Query q = qm.createQuery("Select * from mastheadLogo", "sql");
QueryResult qr = q.execute();
Collection content = qr.getContent();
Iterator it = content.iterator();
int count = 0;
while (it.hasNext()) {
count++;
Content currentContent = (Content) it.next();
String logoName =
currentContent.getNodeData(logoNameProperty).getString();
String logoUuid = currentContent.getUUID();
SelectOption option = new SelectOption("[" + count+ "] " + logoName,
logoUuid);
}
if (count == 0) log.warn ("...hey, something has gone wrong... 0
content found!");
this.setOptions(options);
} catch (Exception e) {
log.warn("Can not retrieve logos. Message: {}" + e.getMessage());
}
}
*************************************************
Thanks for your help...
Matteo
----------------------------------------------------------------
for list details see
http://documentation.magnolia.info/
----------------------------------------------------------------