grails - URL Mapping - Replacing characters in a parameter pulled from a database -
i trying figure out, how modify parameter being integrated url mapping using.
static mappings = { "/$controller/$action?/$id?/(.$format)?" { constraints { // apply constraints here } } name test1: "/.../$title/..."{ controller = "study" action = "st_show" } name test2: "/.../$title/..."{ controller = "search" action = "se_show" }
the parameter $title pretty dataset, pulled database , transmitted in following format [ title ]. there square brackets in front , behind string , words seperated through blanks.
if creating link through g:link params nested in, gets put url pulled database. attempting create seo-urls, present title of publication devided hyphens instead of url-encoded "%20".
until now, able generate dynamic urls looking this:
http://localhost:8080/projectname/show/%5ballgemeine%20bevölkerungs[...]/782/...params...
furthermore implemented through jquery, though should static , users should able copy link open page - wouldn't possible when changing url client-side while loading page.
is there way define function replaceall.(' ', '-'), can invoked onto parameter in mapping replace blanks hyphens , f.e. square brackets empty character? that's pretty much, wasn't able come through documentation.
thank in advance help!
i managed solve problem creating service function containing regex , executing function onto parameter title in g:link, firstly converted string, gets passed function.
<g:link controller="study" action="st_show" params="[data: data, ... title: conversionservice.convert(fieldvalue(bean: path).tostring(), ... data: data)]"></g:link>
and function in conversionservice
public static string convert(string title){ title = title.replaceall("\\s", "-").replaceall("[^0-9a-za-z\\-]", ""); return title; }
Comments
Post a Comment