2017-01-18 1 views
0

Ich habe eine Grails-Anwendung, die ich für (Namen der Anwendung, Bild etc etc.) eine globale Konfigurations-Seite bauteGrails globale Variable basierte Umleitung

ich es jede URL-Anfrage umleiten möchte, wenn ein boolean false ist . Ich würde sehen, diese so etwas wie:

AppConfiguration config = AppConfiguration.findAll().get(0); 
if(config == null || !config.hasBeenConfigured) 
{ 
    redirect([controller :"AppConfiguration", action:"index"]) 
} 

Alle Ideen, wie dies zu tun, ohne durch die 100s von Controllern zu Schleppen dies in hinzuzufügen

Grails Version 3.0.8

Dank

.
+0

Welche Version von Grails? –

+0

@JoshuaMoore Entschuldigung! Version 3.0.8, ich werde die Frage jetzt auch aktualisieren. –

Antwort

0

Okay, ich habe eine Lösung gefunden.

Jeder Controller einen Haupt Layout für Ressourcen usw. über implementiert:

<meta name="layout" content="main"/> 

Also in diesem main.gsp ich die folgenden Bit-Code hinzugefügt:

<g:set var="config" bean="configurationService"/> 
<script> 
    var shouldRedirect = ${!config.hasBeenConfigured()}; 

    if(shouldRedirect && window.location.href.indexOf("AppConfiguration") == -1) 
    { 
     window.location.href = window.location.origin + "/AppConfiguration/index"; 
    } 
</script> 

und erstellt so genannte grails Service ConfigurationService wie folgt:

class ConfigurationService { 

    def hasBeenConfigured() 
    { 
     return AppConfiguration.instance.hasBeenConfigured; 

    } 

    def getApplicationName() 
    { 
     return AppConfiguration.instance.applicationName; 
    } 
}