Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't need the <code>${}</code> in the <code>from</code> option</p> <pre><code>g.select(name : searchfield.fieldName, class : "fillWidth searchfield", multiple : "true", from : searchfield.fieldFrom, optionKey : searchfield.fieldKey, optionValue : searchfield.fieldValue) </code></pre> <p>In Groovy code <code>${}</code> is a way to put Groovy expressions inside double quoted GStrings, if you're not in a GString you can just use the expression directly without wrapping it in <code>${}</code>.</p> <hr> <p><strong>Edit</strong> from your comment</p> <blockquote> <p>The fieldFrom at this point is a string which would get its value from a database. So the value in the DB is "Car.list()" which in the prototype I need to convert to a bound able or execute-able line of code.</p> </blockquote> <p>It's not generally recommended to allow your app to execute arbitrary snippets of Groovy code provided by users (for obvious security reasons). As long as the code snippets come from a secure source such as a trusted admin user then fair enough, it is possible using <code>GroovyShell</code></p> <pre><code>def from = new GroovyShell().evaluate(searchfield.fieldFrom) </code></pre> <p>but this is likely to be rather inefficient, creating a new classloader and parsing and compiling a whole Groovy script class every time. If the <code>fieldFrom</code> values are intended to always be pulling something from the database (i.e. they'll always be something like <code>Car.list()</code> or <code>Vehicle.findAllByNumberOfWheelsGreaterThan(2)</code>, rather than arbitrary Groovy like <code>[1,2,3]</code>) then it might be better to store HQL expressions in <code>fieldFrom</code> and run them using <code>executeQuery</code></p> <pre><code>def from = AnyDomainClass.executeQuery(searchfield.fieldFrom) </code></pre> <p>(<code>executeQuery</code> is a static GORM method, you need to call it on a specific domain class but it can return results of any type). The HQL equivalent of <code>Car.list()</code> would be "<code>from Car</code>", the equivalent of <code>Vehicle.findAllByNumberOfWheelsGreaterThan(2)</code> would be "<code>from Vehicle where numberOfWheels &gt; 2</code>", etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload