grails

Way to deep traverse a Groovy object with dot in string using GPath

不羁的心 提交于 2020-01-11 06:05:44
问题 The situation I have is that I'm querying MongoDB with a string for a field that is more than one level deep in the object hierarchy. This query must be a string. So for example I'm querying for something like this in Groovy: def queryField = 'a.b.c' //this is variable and can be different every time def result = mongodb.collection.findOne([queryField:5]) The problem no arises that in the result I want to find the value of the nested field. With GPath I could go one level deep and get a's

resource plugin error when upgrading from grails 2.3.8 2.4

我怕爱的太早我们不能终老 提交于 2020-01-11 05:31:08
问题 Im following the docs trying to upgrade my project from 2.3.8 to 2.4, but I am encountering these error(s) localhost-startStop-1] ERROR resource.ResourceProcessor - Unable to load resources Message: No signature of method: groovy.util.ConfigObject.getGrailsPlugin() is applicable for argument types: (java.lang.String) values: [lesscss-resources] ->> 5 | run in BootstrapResources - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 46 | doCall in org.grails.plugin.resource

Sql query for insert in grails

夙愿已清 提交于 2020-01-10 10:17:06
问题 How to execute plain sql in grails . I need to use sql query for inserting new record in database . How can we achieve this with out using HQL and gorm relations . thanks 回答1: groovy.sql.Sql simplifies the details of doing JDBC queries. In a Grails app you'd use the constructor that takes a DataSource: import groovy.sql.Sql ... class FooService { def dataSource ... def runSqlQuery(...) { Sql sql = new Sql(dataSource) sql.executeInsert("insert into ...") ... } } See these links for usage tips:

Grails “respond” renders the wrong view when launched from .war file

谁说我不能喝 提交于 2020-01-10 03:19:42
问题 A Grails application has a lot of auto-generated (from standard Grails 2.3.0 scaffolding) code using the new RESTful "respond" feature. For example, the index methods generally look like this: def index(Integer max) { params.max = Math.min(max ?: 10, 100) respond Alpha.list(params), model:[alphaInstanceCount: Alpha.count()] } This works completely fine when the application is run as "grails run-app" however fails when the application is packaged as a .war and launched that way inside a non

Rendering 'as JSON' in Grails with conditional operator doesn't render correctly

♀尐吖头ヾ 提交于 2020-01-09 11:15:51
问题 Came across this strange result today trying to render a list of objects as JSON in Grails 2.0.4...(i know i'm gonna regret asking this on account of something right under my nose... updated 5/26, my prediction was correct, see below :-)) This works fine; the JSON renders correctly in the browser... def products = [] //ArrayList of Product objects from service def model = (products) ? [products:products] : [products:"No products found"] render model as JSON ..so why doesn't this shortened

Rendering 'as JSON' in Grails with conditional operator doesn't render correctly

≡放荡痞女 提交于 2020-01-09 11:12:53
问题 Came across this strange result today trying to render a list of objects as JSON in Grails 2.0.4...(i know i'm gonna regret asking this on account of something right under my nose... updated 5/26, my prediction was correct, see below :-)) This works fine; the JSON renders correctly in the browser... def products = [] //ArrayList of Product objects from service def model = (products) ? [products:products] : [products:"No products found"] render model as JSON ..so why doesn't this shortened

Grails not encoding the unicode characters properly

依然范特西╮ 提交于 2020-01-09 07:50:12
问题 In my grails app, the unicode characters are not being encoded properly. I'm using grails 1.3.7 and tomcat 7.0.22. Following are the settings that I've configured in my app for unicode support: - Set grails.views.gsp.encoding and grails.converters.encoding="UTF-8" in Config.groovy - Set encoding to UTF-8 in meta tag in the .gsp pages - Specified 'useUnicode=true&characterEncoding=UTF-8' to the MySql connection URL (DB has characterset set to UTF-8) - Set URIEncoding="UTF-8"

Grails command object data binding

隐身守侯 提交于 2020-01-09 06:20:20
问题 Grails has very good support for binding request parameters to a domain object and it's associations. This largely relies on detecting request parameters that end with .id and automatically loading those from the database. However, it's not clear how to populate the associations of a command object. Take the following example: class ProductCommand { String name Collection<AttributeTypeCommand> attributeTypes ProductTypeCommand productType } This object has a single-ended association with

How to create functional test directory in grails

此生再无相见时 提交于 2020-01-07 09:25:35
问题 I am trying to create functional tests in grails. I have integration and unit tests. But i am unable to create functional tests directory. I am using grails 2.4.5 version 回答1: Grails 2 does not ship with functional testing capabilities. Noted in the documentation here. Using a plugin for functional testing is the recommended practice. Grails does not ship with any support for writing functional tests directly, but there are several plugins available for this. Canoo Webtest - http://grails.org

Grails empty entry into the database

拥有回忆 提交于 2020-01-07 09:24:09
问题 I have been struggling with trying to create/save multiple instances at once in Grails, now I am almost there with the following code but when I hit save an empty row of options is created, can anyone help me with this please see these two questions to see what I want to achieve How to save multiple object from one view using Grails Grails one to many relationship view <g:textField name="question" value="${multipleChoiceQuestionInstance?.question}"/><br/> <div class="fieldcontain ${hasErrors