我想對下面的類有一個過濾器(「辯論」)。默認情況下,我得到一個包含標題,發佈和url的過濾器。這很好,但當我嘗試過濾URL時,我得到以下異常。 「java.lang.String不能轉換爲java.net.URL」,查看底部的完整堆棧跟蹤。Grails插件filterPane associatedProperties不適用於java.net.URL
爲了解決這個問題,我添加了url.authority的associatedProperties,見下文。我想,因爲filterpane是比較字符串,我會給它一個字符串(url.authority)。
問題是url.authority的associatedProperties永遠不會出現在過濾器上。
我通過filterpane碼看,我可以看到下面的代碼
// Extract out the associations. These are handled separately from simple properties.
List associatedProps = persistentProps.findAll {
it.association == true && !it.type.isEnum()
}
這是不包括url.authority因爲url.authority不是一個單獨的域。我可以把網址放到一個域中,我猜它會起作用,但我寧願不這樣做,因爲它正在改變我的底層代碼以迎合插件,這是非常糟糕的做法。
class Debate
{
String title;
Date published;
URL url;
static constraints =
{
url nullable : false, unique : true
}
}
順便說一下,我試過沒有excludeProperties,它沒有區別。
<filterpane:filterPane dialog="true" domain="com.content.OpenDebate"
associatedProperties="url.port" excludeProperties="url"/>
堆棧跟蹤
java.lang.String cannot be cast to java.net.URL. Stacktrace follows:
java.lang.ClassCastException: java.lang.String cannot be cast to java.net.URL
at grails.orm.HibernateCriteriaBuilder.invokeMethod(HibernateCriteriaBuilder.java:1587)
at org.grails.plugin.filterpane.FilterPaneService$_doFilter_closure4.doCall(FilterPaneService.groovy:153)
at org.grails.plugin.filterpane.FilterPaneService.doFilter(FilterPaneService.groovy:156)
at org.grails.plugin.filterpane.FilterPaneService.filter(FilterPaneService.groovy:12)
at com.keane.reg.opendebate.OpenDebateController$_closure1.doCall(OpenDebateController.groovy:29)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
BTW:爲什麼在世界上我會在標籤restriced我可以用它來形容這個職位。我必須擁有1500或更高的聲望才能包含filterpane和associatedproperties這兩個字。這使得我的帖子不太可能得到回答。