Grails g: link - include the application name in the resulting binding href attribute

This GSP:

<g:link controller="book" action="show" id="5">Example</g:link>

leads to the following HTML:

<a href="/book/show/5">Example</a>

This applies to the HTTP host. If your site runs on http: // localhost: 8080 , that’s fine.

During development, the application will run more often on http: // localhost: 8080 / appName .

In such cases, the above link will not work - this will lead to an absolute URL http: // localhost: 8080 / book / show / 5 instead of the required http: // localhost: 8080 / appName / book / show / 5

What changes are needed for the above GSP for the name of the application that should be present in the received href application?

+3
source share
5 answers

grails.app.context , , . , , , http://localhost:8080/appName. (, http://locahost:8080/), Config.groovy:

grails.app.context = "/"

, URL-, g:link, .

+3

, meta GSP.

, , :

<g:meta name="app.name"/>

application.properties, .

, , , . , g:. :

<g:set var="help" value="http://localhost:8080/${meta(name:"app.name")}/help" />

Grails , .

+2

<g:link> , , , , http://localhost:8080 prod http://mycoolsite.com - .

g:resource css, javascript .. - GSP, (, "appName" ), .

+1

I think grails.serverURL is needed for this. You defined this configuration variable in Config.groovy, for more information see the configuration documentation for Grails .

Hope this helps!

0
source

In the createLink tag, your appname / context parameter is automatically included.

Here is the doc link for it.

0
source

Source: https://habr.com/ru/post/1793686/


All Articles