Hello Ognen! I have made some similar behavior for a past Tapestry version, i think 5.0.2, but the idea should be standard: 1.- Read the files inside the pages folder that is subfolder of tapestry.app-package init param, of course filtering with a FilenameFilter, instead of that you can build a Tree of pages. 2.- Those file names are candidates for the navigation, next you have to get the Page instance for each result in step 1. You can do it with the help of ComponentSource that tapestry provides (just inject that in your service), with the page instance in hand you have to ask if that instance has the annotation you want. maybe this code can help: public Page getPage(String pageName) { Component page = null; try { page = _componentSource.getPage(pageName); Navigation navigation = page.getClass().getAnnotation(Navigation.class); if (navigation != null) { Messages messages = _componentMessageSource.getMessages( page.getComponentResources().getComponentModel(), page.getComponentResources().getLocale()); return new Page(pageName,messages.get(TITLE_KEY),navigation.needslogin()); } else { _log.debug("The page '" + pageName + "' is not annotated with the annotation '" + Navigation.class.getSimpleName() + "'"); return null; } } catch (IllegalArgumentException e) { _log.debug("The page '" + pageName + "' has no title in it´s properties file"); return null; } }
This method takes the pageName as a parameter and returns a Page instance that is just a simple bean with name an title properties. This method is called by each candidate page that were collected by the method that reads the folder where the pages are. Note that the ComponentSource and ComponentMessagesSource were used. One more think, when you call _componentSource.getPage(pageName); tapestry will create the instance of the page, as the documentation says that process is really involved and if you have a lot of pages the process will consume a lot of time, so it´s better to call this process on application start. ________________________________ From: Ognen Ivanovski [mailto:[EMAIL PROTECTED] Sent: Mon 7/16/2007 11:21 AM To: Tapestry users Subject: [T5] navigation component Hi everyone, I am trying to build up a T5 navigation component. The general idea is: - it should figure out the navigational tree based on the pages available around - Showing a page in the navigational component should be a matter of tagging a component with an annotation (@Navigable, or @ShowsInNavigation) - Additional info (i.e. display text, icon, etc..) also from annotation - The grouping of pages should be based on sub packages in the *.pages) - package-info.java would be used for annotating the groups (text, icons) So here are the questions: 1) How can I iterate through all pages present in an app? 2) How can I access the annotations on a Page class. I saw the Component / ComponentModel interfaces but they do not offer access to the annotations. Perhaps the @Meta annotation can help here but I don't want to limit myself to strings. -- Ognen Ivanovski | [EMAIL PROTECTED] phone +389 -2- 30 64 532 | fax +389 -2- 30 79 495 Netcetera | 1000 Skopje | Macedonia | http://netcetera.com.mk <http://netcetera.com.mk/> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]