Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

g:createLink resource="" should allow specifying contollerName #479

Open
codeconsole opened this issue Sep 7, 2024 · 2 comments
Open

g:createLink resource="" should allow specifying contollerName #479

codeconsole opened this issue Sep 7, 2024 · 2 comments
Assignees

Comments

@codeconsole
Copy link
Contributor

codeconsole commented Sep 7, 2024

Given the following:

class Sample {
    String name
}

class Sample2Controller {
    static scaffold = Sample
}

all the links should work, but they don't. They all end up pointing to /sample/$action

this is due to the resource option in links. This could be fixed by also allowing to override resource with controllerName, but does not perform as expected..

@codeconsole codeconsole self-assigned this Sep 7, 2024
@codeconsole
Copy link
Contributor Author

Closure createLink = { attrs ->
return doCreateLink(attrs instanceof Map ? (Map) attrs : Collections.emptyMap())
}
@CompileStatic
protected String doCreateLink(Map attrs) {
Map urlAttrs = attrs
if (attrs.url instanceof Map) {
urlAttrs = (Map)attrs.url
}
Map params = urlAttrs.params && urlAttrs.params instanceof Map ? (Map)urlAttrs.params : [:]
HttpServletRequest req = (HttpServletRequest)getProperty('request')
HttpServletResponse res = (HttpServletResponse)getProperty('response')
def flowExecutionKey = req.getAttribute('flowExecutionKey')
if (flowExecutionKey) {
if (attrs.controller == null && attrs.action == null && attrs.url == null && attrs.uri == null) {
urlAttrs[LinkGenerator.ATTRIBUTE_ACTION] = GrailsWebRequest.lookup().actionName
}
}
if (urlAttrs.event) {
params."_eventId" = urlAttrs.remove('event')
urlAttrs.params = params
}
String generatedLink = linkGenerator.link(urlAttrs, req.getAttribute('characterEncoding')?.toString())
generatedLink = processedUrl(generatedLink, req)
return useJsessionId ? res.encodeURL(generatedLink) : generatedLink
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant