[opencms-dev] get all categories listed

Sandrine Prousteau s.prousteau at eurelis.com
Mon Oct 15 18:34:07 CEST 2012


Hi
You should test with :

readCategories(cmso, CATEGORY_NAME, false, REFERENCE_PATH)

Be careful with ending "/", I'm not sure...



-----Message d'origine-----
De : opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] De la part de kaybe
Envoyé : lundi 15 octobre 2012 15:14
À : opencms-dev at opencms.org
Objet : [opencms-dev] get all categories listed


I'm trying to list all categories and iterate over them, using CmsCategoryService with method readCategories. But I get no results, no exception either, just an empty list. I made a category folder 'theme' in '/sites/default/_catagories/' and made some categories under this 'theme'
category.
Is this the wrong method? 
I tried different paths like "_categories", "_categories/", etc...


<%@page buffer="none" session="false" import="java.util.*, org.opencms.file.*, org.opencms.jsp.*, org.opencms.util.*, org.opencms.relations.CmsCategoryService" %> <%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %> <%!
public void buildCategoryMap(CmsJspActionElement cms, String uri, java.io.Writer out) throws Exception {
	final String REFERENCE_PATH = "/sites/default/_categories/";
	final String CATEGORY_NAME = "theme"; 
	final boolean INCLUDE_SUB_CATEGORIES = false;
	int amount = 0;
	CmsObject cmso = cms.getCmsObject();
	CmsCategoryService catService = CmsCategoryService.getInstance(); // Get the singleton
	try {
		List res = catService.readCategories(cmso, REFERENCE_PATH, false, CATEGORY_NAME); 
		Iterator i = res.iterator();
		
		while (i.hasNext()) {
			
			amount++;
			out.write("<li>" + amount + "</li>");
		}
	}
		catch (Exception e) {
		out.write("<li>something is very wrong</li>");
	}
}

	
--
View this message in context: http://old.nabble.com/get-all-categories-listed-tp34558113p34558113.html
Sent from the OpenCMS - Dev mailing list archive at Nabble.com.

_______________________________________________
This mail is sent to you from the opencms-dev mailing list To change your list options, or to unsubscribe from the list, please visit http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev








More information about the opencms-dev mailing list