2016-09-06 43 views
1

我使用G:sortableColumn我的表,但我得到這個錯誤:G:sortableColumn缺少控制器的名稱(我如何可以通過控制器的名字?G:sortableColumn)

通過UrlMappingException引起:無法爲映射 [/()/()?/(*)?]和參數[{sort = firstName,order = asc, action = list}]創建URL。參數[控制器]是必需的,但不是指定的 !

這是我的代碼:

<g:sortableColumn property="firstName" title="FirstName"/> 

這是我的課:

package medicalautomation 

class InformationDocs { 

    String firstName 
    String lastName 
    String idNum 
    String sex 
    String bloodType 
    Date birthDay 
    String job 
    String backGround 
    Double weight 
    Double height 
    Double bloodPressure 
    Double bloogSugar 
    String phoneNum 
    String address 
    String description 


    static constraints = { 
     firstName() 
     lastName() 
     idNum() 
     sex() 
     bloodType() 
     birthDay() 
     job() 
     backGround(maxSize:5000) 
     weight(nullable: true) 
     height(nullable: true) 
     bloodPressure(nullable: true) 
     bloogSugar(nullable: true) 
     phoneNum(maxSize: 20) 
     address(maxSize: 200) 
     description(maxSize: 5000) 


    } 
} 

那麼其明顯的是,當我使用它在另一個GSP頁面一個比它是鏈接到控制器,我必須通過控制器名稱。問題是我不知道如何,我不確定它是否與URL映射有關。

感謝您的幫助

我的GSP代碼:

<!doctype html> 
<html> 
<head> 
<meta name="layout" content="main"/> 
<g:javascript library="jquery" plugin="jquery" /> 
<title>Welcome to Grails</title> 
</head> 
<body> 
<div class="topnav"> 
    <p style="color: white">Top Nav</p> 
</div> 
<div class="sidenav"> 
<div class="sidenavcontent" > 
    <h1>HELLO!!!</h1> 
    <ul> 
    <g:each var="c" in="${grailsApplication.controllerClasses.sort { it.fullName } }"> 
    <li><g:link controller="${c.logicalPropertyName}">${c.fullName}</g:link></li> 
    </g:each> 
    </ul> 
<table> 
    <tr> 
    <g:sortableColumn property="firstName" title="FirstName"/> 
    <g:sortableColumn property="lastName" title="LastName"/> 
    <g:sortableColumn property="idNum" title="ID Number"/> 
    </tr> 
    <g:each in="${medicalautomation.InformationDocs.list()}" var="info"> 
    <tr> 
    <td><g:remoteLink id="${info.id}" controller="informationDocs" action="show" update="showdetails">${info.firstName}</g:remoteLink></td> 
    <td>${info.lastName}</td> 
    <td>${info.idNum}</td> 
    </tr> 
    </g:each> 
    </table> 
</div> 
</div> 
<div class="bodycont"> 
<div id="showdetails"></div> 
</div> 

我使用PARAMS地圖發送控制器並正確調用名單行動但有是一個問題:

我改名單的行動,並將其重定向到GSP頁面,G:sortableColumn是,但它似乎是表的順序不changing.This是我的代碼在控制器:redirect(uri: "?sort=${params.sort}&order=${params.order}")

+0

你可以把你的GSP代碼放在你使用** sortableColumn **的地方以便更好的理解。 –

+0

@ajaypanchal我更新了文章 – Navid

+2

嘗試在 Vahid

回答

1

正如我理解正確的話, gsp-page不是 意見 - > medicalautomation.informationDocs.index one?

...如果要將可排序列重定向到其他控制器,則必須承擔責任,爲此控制器提供與列表方法相同的數據,該控制器最初顯示gsp頁面,並且必須在響應指定此GSP頁...(因爲點擊排序列後,再次顯示在同一頁面,用列表,由列名排序)

,因此,您

<g:each in="${medicalautomation.InformationDocs.list()}" var="info"> 

讓我困惑了一下,因爲那裏你直接調用了DomainClass-list方法而沒有參數(其中指定了排序順序)我認爲你的排序會被丟棄,即使你設法顯示它,但沒有例外......?

在我要顯示的依賴列表有限的情況下,我經常使用jQuery-DataTable。其中有可能排序線等內置。

和:

在我想根據顯示數據的小集合的情況下,我通常使用jQuery.ajax調用來獲取數據,並通過jQuery的/ JavaScript的修改HTML ...

希望我能幫上忙。

+0

是的,它不是控制器gsp。 併爲解釋。如你所說,點擊g:sortableColumn調用控制器的列表動作 – Navid

相關問題