Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 2.0-RC1
-
Fix Version/s: 2.3-M2
-
Component/s: View technologies
-
Environment:OS: Win XP SP3
IDE: Netbeans 7.0.1/Tomcat 7.0.1
Grails: 2.0.0.RC1
Description
Hi,
in our project "myProject" we have found a regression migrating it from Grails 1.3.6 to Grails 2.0.0.RC1.
The issue occurs during the "evaluate" method in a GSP page. More in detail, we use it in the g:select tag below:
<g:select name="${reportFieldInstance.code}" noSelection="${['null':'']}" from="${evaluate(reportFieldInstance.fromClause)}" optionKey="${reportFieldInstance.optionKey}"/>
reportFieldInstance.fromClause is a String that we evaluate at runtime in order to pass the list of a domain class dinamically.
This works fine with version 1.3.6 but in 2.0.0 Release Candidate 1 we are facing the following error:
| Error 2011-11-09 11:08:16,268 ["http-bio-8080"-exec-1] ERROR errors.GrailsExceptionResolver - GroovyCastException occurred when processing request: [GET] /myProject/report/print/2 Cannot cast object 'com.bla.bla.bla.myProject.Group.list()' with class 'java.lang.String' to class 'java.io.File'. Stacktrace follows: Message: Error processing GroovyPageView: Error executing tag <g:form>: Error evaluating expression [evaluate(reportFieldInstance.fromClause)] on line [69]: Cannot cast object 'com.bla.bla.bla.myProject.Group.list()' with class 'java.lang.String' to class 'java.io.File' Line | Method ->> 93 | runTask in \grails-app\views\report\print.gsp - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Caused by GrailsTagException: Error executing tag <g:form>: Error evaluating expression [evaluate(reportFieldInstance.fromClause)] on line [69]: Cannot cast object 'com.bla.bla.bla.myProject.Group.list()' with class 'java.lang.String' to class 'java.io.File' ->> 93 | doCall in C:/svn/CIBIT-LAPPS/groovy/NetBeansProjects/myProject/grails-app/views/report/print.gsp - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Caused by GroovyPagesException: Error evaluating expression [evaluate(reportFieldInstance.fromClause)] on line [69]: Cannot cast object 'com.bla.bla.bla.myProject.Group.list()' with class 'java.lang.String' to class 'java.io.File' ->> 69 | doCall in C:/svn/CIBIT-LAPPS/groovy/NetBeansProjects/myProject/grails-app/views/report/print.gsp - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Caused by GroovyCastException: Cannot cast object 'com.bla.bla.bla.myProject.Group.list()' with class 'java.lang.String' to class 'java.io.File' ->> 95 | doCall in C__svn_CIBIT_LAPPS_groovy_NetBeansProjects_myProject_grails_app_views_report_print_gsp$_run_closure2_closure20_closure55 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 121 | doCall in C__svn_CIBIT_LAPPS_groovy_NetBeansProjects_myProject_grails_app_views_report_print_gsp$_run_closure2 | 124 | run . . in C__svn_CIBIT_LAPPS_groovy_NetBeansProjects_myProject_grails_app_views_report_print_gsp | 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker | 908 | run . . in '' ^ 662 | run in java.lang.Thread
Replacing the evaluate(string) with the string itself the GSP page works fine:
<g:select name="${reportFieldInstance.code}" noSelection="${['null':'']}" from="${com.bla.bla.bla.myProject.Group.list()}" optionKey="${reportFieldInstance.optionKey}"/>
So the issue seems to be related to the way Grails perform the evaluate method in a GSP.
Thanks and best regards
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
The content of groovy.lang.Script is:
public Object evaluate(String expression) throws CompilationFailedException { GroovyShell shell = new GroovyShell(getClass().getClassLoader(), binding); return shell.evaluate(expression); }as a workaround you could try $
{new Script(binding).evaluate(reportFieldInstance.fromClause)}.