Grails“丢失”在页面上进行任何链接时自定义URL映射 [英] Grails "loses" custom URL mapping when following any links on the page

查看:118
本文介绍了Grails“丢失”在页面上进行任何链接时自定义URL映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,用户可以通过两种方式浏览地图(如缩略图和列表)。

  / map /浏览
/ map / list

现在,我想限制这些视图显示特定用户的地图,例如通过

  / user / 3 / browse 
/ user / 3 / list

所以我创建了映射:

<$ p $ / user / $ userId / browse{
controller =map
action =browse
}

/ user / $ userId / list{
controller =map
action =list
}

现在,我可以转到 / user / 3 / browse ,但只要点击分页链接或更改分页过滤器,网址可以回到 / map / browse 如果我在控制器中将 userId 设置为 null ,则会出现错误:


错误500:错误处理essing GroovyPageView:执行标记时出错:无法为映射[/ user /(*)/ list]和参数[[action:list,controller:map,max:20, offset:0,sort:uploadDate,order:desc,userId:null,totalMaps:30]]。参数[userId]是必需的,但未指定! at /views/map/browse.gsp:26


分页的工作原理如下:

 < div class =paginateButtons> 
< / div>

我能做些什么,或者什么是实现我想要的正确方式? p>

我不一定需要这个URL映射,我只需要一个很好的方式来说:仅显示一个用户的地图

解决方案

看来问题不在于您的URL映射配置,而在于您创建链接的方式。我认为如果您使用命名的URL映射:它比现在更清晰,创建分页链接时只需指定url名称。例如:

在UrlMappings.groovy中:

  static mappings = {

name account详细信息:/ details / $ acctNumber{
controller ='product'
action ='accountDetails'
}
}

在视图中 - gsp页面:

 < g:link mapping =accountDetailsparams =[acctNumber:'8675309']> 
显示帐户
< / g:link>


I have an application where users can browse maps in two ways (like thumbnails and in a list)

/map/browse
/map/list

Now, I would like to restrict these views to just show maps of a specific user, for example through

/user/3/browse
/user/3/list

So I created the mapping:

"/user/$userId/browse" {
  controller = "map"
  action = "browse"
}

"/user/$userId/list" {
  controller = "map"
  action = "list"
}

Now, I can go to /user/3/browse, but as soon as I click on a pagination link or change the pagination filters, the URL goes back to /map/browse.

Also, if I set the userId to null in the controller, I get the error:

Error 500: Error processing GroovyPageView: Error executing tag : Unable to create URL for mapping [/user/(*)/list] and parameters [["action":"list", "controller":"map", "max":20, "offset":0, "sort":"uploadDate", "order":"desc", "userId":null, "totalMaps":30]]. Parameter [userId] is required, but was not specified! at /views/map/browse.gsp:26

The pagination works as follows:

<div class="paginateButtons">
    <g:paginate controller="map" action="browse" total="${mapInstanceTotal}"></g:paginate>
</div>

What can I do against that or what would be the correct way of implementing what I want?

I don't necessarily need to have that URL mapping, I only need a nice way of saying: "Display maps of only one user"

解决方案

It seems that the problem is not at your URL mapping configuration ,but in your way to create link. I think it's better if you use Named URL Mapping : it's clearer than your approach now, and when create link for pagination you only need to specify the url name. For example:

In UrlMappings.groovy:

static mappings = {

    name accountDetails: "/details/$acctNumber" {
        controller = 'product'
        action = 'accountDetails'
    }
}

In view - gsp page:

<g:link mapping="accountDetails" params="[acctNumber:'8675309']">
    Show Account
</g:link>

这篇关于Grails“丢失”在页面上进行任何链接时自定义URL映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆