2011-10-19 21 views
2

我想重寫我的模型之一的CRUD模塊的list()函數。如何覆蓋CRUD/list()函數?玩!框架

我發現this谷歌組基本上是我遇到的問題。

基本上我想根據certian類別過濾列表,我嘗試這樣做:

控制器

public static void list(string category){ 
    List<Duty> object = Duty.getByCategory(category); 
    render(object); 
} 

模型

public static List<Duty> getByCategory(String category){ 
    List<Duty> result = Duty.find("select distinct d from Duty d join " + 
     "d.category c where c.name = ? order by d.name", category).fetch(); 
    return result; 
} 

我收到以下錯誤:

Template execution error

如何覆蓋列表操作?

任何幫助將不勝感激。

回答

3

看來你是重寫控制器而不是模板。在CRUD列表方法的簽名是this one,略有不同的是你的:

​​3210

你會發現,渲染()是經過多,你做更多的參數,而且很可能他們是不可選的。嘗試爲它們提供值。

1

可以重寫CRUD列表法,並在那裏添加傳遞許多參數的過濾器,例如:

public static void list(int page, String search, String searchFields, String orderBy, String order) { 
    ObjectType type = ObjectType.get(getControllerClass()); 
    notFoundIfNull(type); 
    if (page < 1) { 
     page = 1; 
    } 
    String where = "nameAttribute =" + value; 

    List<Model> objects = type.findPage(page, search, searchFields, orderBy, order, where); 
    Long count = type.count(search, searchFields, where); 
    Long totalCount = type.count(null, null, where); 
    try { 
     render(type, objects, count, totalCount, page, orderBy, order); 
    } catch (TemplateNotFoundException e) { 
     render("CRUD/list.html", type, objects, count, totalCount, page, orderBy, order); 
    } 
} 
0

嘗試致電該重寫方法從view(xtml)

<form action="@{Controler.overrideList()}" method="POST"> 

而且使用以前的代碼,並在where = "..."

添加傳遞許多參數的過濾器