Grails, finding available views (.gsp) at runtime

Is there an easy way for my grails app to find the viewlist (* .gsp) available at runtime.

Ideally, the solution will work for both application servers that are unpacking the WAR and those that are not unpacking the WAR.

Thank!

+2


source to share


1 answer


Unfortunately it differs for dev environment and when deployed in war:



import org.codehaus.groovy.grails.web.context.ServletContextHolder as SCH

def gsps = []
if (grailsApplication.isWarDeployed()) {
   findWarGsps '/WEB-INF/grails-app/views', gsps
}
else {
   findDevGsps 'grails-app/views', gsps
}

private void findDevGsps(current, gsps) {
   for (file in new File(current).listFiles()) {
      if (file.path.endsWith('.gsp')) {
         gsps << file.path - 'grails-app/views/'
      }
      else {
         findDevGsps file.path, gsps
      }
   }
}

private void findWarGsps(current, gsps) {
   def servletContext = SCH.servletContext
   for (path in servletContext.getResourcePaths(current)) {
      if (path.endsWith('.gsp')) {
         gsps << path - '/WEB-INF/grails-app/views/'
      }
      else {
         findWarGsps path, gsps
      }
   }
}

      

+4


source







All Articles