我在域类中有静态方法返回一个url.我需要动态构建该URL,但g.link无法正常工作.
static Map options() {
// ...
def url = g.link( controller: "Foo", action: "bar" )
// ...
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Apparent variable 'g' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable from a static context.
You misspelled a classname or statically imported field. Please check the spelling.
You attempted to use a method 'g' but left …Run Code Online (Sandbox Code Playgroud) 我是Grails的新手,我继承了现有的应用程序.我有一个大文件message.properties,我想修剪,以删除不再使用的密钥.
在Django中,有一个命令makemessages遍历所有代码库并收集所有需要转换的字符串,将它们添加到消息文件中并注释掉不再存在的条目.Grails有类似的工具吗?如果有帮助,该项目基于1.3.9版本.
鉴于以下应用程序的风格:
productFlavors {
pro {
applicationId = "com.example.my.pkg.pro"
}
free {
applicationId = "com.example.my.pkg.free"
}
}
Run Code Online (Sandbox Code Playgroud)
我需要声明GCM权限:
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
<application ...>
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gcm" />
</intent-filter>
</receiver>
<service android:name=".GcmIntentService" />
</application>
Run Code Online (Sandbox Code Playgroud)
当com.example.gcm´必须更换com.example.my.pkg.pro或者com.example.my.pkg.free根据当前的味道.
如何配置清单以自动选择applicationId字段中定义的包?
我正在使用ag:select标签,如下所示:
<td><g:select name="newCity"
id="${'newCity_' +cityData.uid}"
from="${cityData.name}"
value="${cityData.someValue}"
noSelection="${['null':'Select City...']}" class="newCity" />
</td>
Run Code Online (Sandbox Code Playgroud)
它呈现以下HTML:
<td>
<select name="newCity" id="newCity_abc" class="newCity" >
<option value="null">Select City...</option>
<option value="A" >A</option>
<option value="B" >B</option>
<option value="C" >C-</option>
<option value="D" >D</option>
</select>
</td>
Run Code Online (Sandbox Code Playgroud)
但是,我希望我的HTML看起来像这样; 因为我正在做一些javascript验证,所以插入了类:
<td>
<select name="newCity" id="newCity_abc" class="newCity" >
<option value="null">Select City...</option>
<option value="A" class="populated" >A</option>
<option value="B" class="notpopulated" >B</option>
<option value="C" class="populated" >C</option>
<option value="D" class="notpopulated" >D</option>
</select>
</td>
Run Code Online (Sandbox Code Playgroud)
这可能吗?
我是否需要创建自定义标记库才能实现此目的?
任何帮助将不胜感激,谢谢!
我有一个选择的TYPES框,每个类型都有自己的PARAMETERS.TYPES选择框将触发一些调用模板的AJAX并在我的视图上呈现PARAMETER选择框.参数由名称:值对组成,因此每个名称可以有许多值.
一些参数需要multiple ='true',以便用户为每个名称选择多个值,而其他参数只需要限制为一个选项.
在我的gsp页面中,我有一堆这样的:
<g:if test="${it?.getKey().toString().equals('PARAMETER_A')}">
<td><g:select multiple="true" optionKey="id" optionValue="value" name="sampleParameters" id="parameter" value="${params?.sampleParameters}" from='${it?.getValue().sort()}'></g:select></td>
</g:if>
<g:if test="${it?.getKey().toString().equals('PARAMETER_B')}">
<td><g:select multiple="true" optionKey="id" optionValue="value" name="sampleParameters" id="parameter" value="${params?.sampleParameters}" from='${it?.getValue().sort()}'></g:select></td>
</g:if>
Run Code Online (Sandbox Code Playgroud)
我的问题是我有一个特定TYPE的6个参数需要选择多个值,其余的则没有.有没有一种方法可以在ag中测试多个东西:if if like like like java in?如:
if(something.equals(PARAMETER_A) || something.equals(PARAMETER_B))
Run Code Online (Sandbox Code Playgroud)
等等
有没有办法在groovy中做类似于java的方法?
我是Groovy的新手,我正在为一些特定的任务编写一个迷你DSL.为此,我一直在尝试解决下面这样的问题:我想通过调用此代码(不使用parantheses)来打印(和/或返回)5:
give me 5
Run Code Online (Sandbox Code Playgroud)
我希望下面这样的定义可行:
def give = {clos -> return clos}
def me = {clos -> println clos; return clos}
Run Code Online (Sandbox Code Playgroud)
但事实上并非如此.你能帮我解释一下如何定义"给"和"我",以便用表达式"给我5"返回值5,其中我必须是一个闭包,给出也可以是metaClass,属性等.
提前致谢!IV
使用Grails 2.0.4,我正在尝试rest-client-builder:1.0.2使用这个...
grails install-plugin rest-client-builder
Run Code Online (Sandbox Code Playgroud)
...但Grails返回以下错误; 我已经尝试过清理,刷新依赖关系等等,继续得到同样的错误......
:: #rest-client-builder;1.0.2: java.text.ParseException: inconsistent module descriptor file found in 'http://plugins.grails.org/grails-rest-client-builder/tags/RELEASE_1_0_2/rest-client-builder-1.0.2.pom': bad organisation: expected='' found='org.grails.plugins';
Run Code Online (Sandbox Code Playgroud)
还尝试将插件作为依赖项链接BuildConfig.groovy,但是我得到了类似的错误......
compile (":rest-client-builder:1.0.2"){ export = false}
grailsCentral: bad organisation found in http://plugins.grails.org/grails-rest-client-builder/tags/RELEASE_1_0_2/rest-client-builder-1.0.2.pom: expected='' found='org.grails.plugins'
Run Code Online (Sandbox Code Playgroud) 我已经为 eclipse kepler 3.5.1 RELEASE 安装了 GGTS 插件。我创建了简单的 grail 项目。但在建设项目时。它的获取错误
构建期间发生错误。 在项目“FirstApp”上运行构建器“Java Builder”时出错。 org.codehaus.groovy.runtime.StringGroovyMethods.plus(Ljava/lang/String;Ljava/lang/CharSequence;)Ljava/lang/String;
如果我们在标记中看到,我发现了这个错误
内部编译器错误:java.lang.NoSuchMethodError:org.codehaus.groovy.runtime.StringGroovyMethods.plus(Ljava/lang/String;Ljava/lang/CharSequence;)Ljava/lang/String; 在 org.codehaus.groovy.grails.transaction.transform.TransactionalTransform.moveOriginalCodeToNewMethod(TransactionalTransform.groovy:259) Config.groovy /FirstApp/grails-app/conf 第 0 行 Java 问题
我正在使用 feroda 17.Eclipse Kepler。
在grails中,我有一个Domain类,可以在BootStap.groovy中查询
def xref = AppXref.find{user_nm == 'john'}
Run Code Online (Sandbox Code Playgroud)
但是,一旦我将代码移动到另一个Domain类的方法,我将有以下错误.
Servlet.service() for servlet [default] in context with path [/myapp] threw exception
Message: Could not obtain current Hibernate Session; nested exception is org.hibernate.HibernateException: No Session found for current thread
Run Code Online (Sandbox Code Playgroud)
这是我在Config.groovy中的hibernate配置
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
// cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
singleSession = true // configure OSIV singleSession mode
flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}
Run Code Online (Sandbox Code Playgroud)
我将cache.use_query_cache更改为true.但它没有任何区别.
我的项目有如下代码:
params.stringValue?.trim().replaceAll('aa', 'a')
Run Code Online (Sandbox Code Playgroud)
我们预计,如果params.stringValue为空,这两者 trim()并replaceAll()不会被调用.
但是我们NullPointerException在这一行上得到的结论replaceAll()是无法在null对象上调用.
我们必须将代码更改为:
params.stringValue?.trim()?.replaceAll('aa', 'a')
Run Code Online (Sandbox Code Playgroud)
为什么上面的第一个代码段不起作用?这是Groovy中的一个错误,它在一次遇到null之后继续评估表达式吗?
grails ×7
groovy ×3
android ×1
dependencies ×1
dsl ×1
eclipse ×1
gradle ×1
grails-orm ×1
java ×1
plugins ×1