需要Groovy/Grails的技术帮助么?让我们一起来研究吧!
有问有答
需要Groovy/Grails的技术帮助么?让我们一起来研究吧!
在grails 工程下运行 grails doc,根据注释生成了文档,但是生成的html中,中文变成了乱码,请问如何处理?
父类放在src/groovy里面发现以下问题:
- 父类的闭包可以继承给子类,并注册为action
- 父类的public void method1(){} 和 def method2{} 会继承给子类,但是不会注册为action
- 父类的有一个属性protected List keywordFilter = [] 并有一个方法protected prepareParams(){}和一个闭包 def c1 = {}分别会输出这个属性。在子类里面覆盖该属性,发现: 继承的prepareParams里面输出的this.keywordFilter 仍然是父类的,而闭包则是子类的.
想请问, 第2和第3个问题是bug么? 如何解决?
文档和一些教程都有叙述,Grails程序可以通过命令发布成War文件,以便于部署在Tomcat或其他WebServer上。而Grails本身也可以通过命令运行在production状态下运行,但不知道这样做性能是否受影响。
如果打成War进行部署,那么很多的文件都不幸的被编译了,修改困难。如果程序微小调整就要重新打包,却又着实有些麻烦。不知道现在使用Grails的成熟产品都是如何部署他们程序的?
Grails自定义标签简单方便,功能强大。但是GSP加载, 比JSP加载多占用很多内存空间,在页面数极多的情况下(不定期代码自动生成许多jsp),计划使用jsp作为表现层。所以希望能有找到一种简单的途径在jsp中调用grails自定义标签。
你好, 我现在正在用grails开发系统,工具是STS。Grails的亮点之一就是有很多现在的插件,但缺点也暴露出来了,就是代码提交到SVN后,在别处下载后,对插件所做的修改无法同步!!!
不知道你们一般怎么解决这个问题的,我在网看上有人说用Maven,有的用SVN,还有的是 BuildConfig.groovy 文件,但没有成功。 希望你能在百忙之中解答。
能否将Grails默认的数据库连接池更换成Proxool?
thanks
有这样一个开发需求:
对于几个GSP文件会同时用到一个头文件来显示页面头部的信息。但是对于不同的页面,头部信息会有不同的显示信息,比如logo等。最初我想用layout来实现,但是不知道该如何向layout中传入参数,来动态实现这个问题。请高手指教。
之前请教的一个问题,自动把json转换为domain
当时的作法如下面的代码.
现在碰到的问题是,一个nullable的时间类型的字段, json无值的时候报错.
Failed to convert property value of type
'org.codehaus.groovy.grails.web.json.JSONObject$Null'
to required type 'java.util.Date' for property 'firstFireTime'
class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
@Override
public void registerCustomEditors(PropertyEditorRegistry registry) {
def formats = GrailsConfig.get("grails.date.formats", List.class)?:
["yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd'T'HH:mm:ss",
"yyyy-MM-dd"];
registry.registerCustomEditor(Date.class, new CustomDateBinder(formats));
}
}
class CustomDateBinder extends PropertyEditorSupport {
private final List<String> formats;
public CustomDateBinder(List formats) {
List<String> formatList = new ArrayList<String>(formats.size());
for (Object format : formats) {
formatList.add(format.toString());
}
this.formats = Collections.unmodifiableList(formatList);
}
@Override
public void setAsText(String s) throws IllegalArgumentException {
if (s){
for (String format : formats) {
SimpleDateFormat df = new SimpleDateFormat(format);
try {
setValue(df.parse(s));
return;
} catch (ParseException e) {
// Ignore
}
}
}
}
}搞了有一会了,搞不出来,在Web应用程序中我写的
StudentService.java
interface StudentService{
List getStudents()
}
StudentServiceImpl .java
class StudentServiceImpl implements StudentService{
static expose = ['hessian', 'rmi']
static remote = [ protocol: 'hessian',
iface: StudentService,
host: 'localhost',
port: '8080',
webcontext: 'Student']
@Override
public List getStudents() {
ArrayList students=Student.list()
println students
return students;
}
}
Student这个类我序列化了。 我已经安装了插件remoting,其实我是按照http://www.grails.org/plugin/remoting一步一步操作的。
在客户端的应用程序写的代码:并且加入了hessian-3.2.0.jar
StudentService.java
interface StudentService{
List getStudents()
}
RemoteClient .java
public class RemoteClient {
public static main(args) {
def url = "http://localhost:8080/GrailsTest/hessian/StudentServiceImpl"
def factory = new HessianProxyFactory()
def basic = factory.create(StudentService.class,url)
println basic.getStudents()
}
}
在web控制台的错误:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'hessian.StudentServiceImpl' is defined
在客户端应用程序的错误:
Exception in thread "main" com.caucho.hessian.client.HessianConnectionException: 500: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8080/GrailsTest/hessian/StudentServiceImpl
我的分析:我知道web这里没有配置好,唉,菜鸟嘛,能力有限。。求帮助了。谢谢哈
最近用Grails开发一个小网站(IDEA 10),想用Gant build整个项目,在该项目下创建了build.gant,想调用Grails下的一些script的task做些事情,于是参考了Grails文档和网上的一些例子,创建了最简单的task:
grailsHome = ant.project.properties."environment.GRAILS_HOME"
//includeTargets << new File ('${grailsHome}/scripts/_GrailsInit.groovy')
includeTargets << grailsScript('_GrailsInit')
//includeTargets << grailsScript('Init')
target(test: 'The default target') {
//depends(init)
println "home = ${grailsHome}"
ant.echo(message: 'running build.gant')
}
setDefaultTarget(test)
可是无论使用哪个includeTargets,都在该行发生问题,
build, line 4 -- Error evaluating Gantfile:
No signature of method: build.grailsScript() is applicable for argument types:
(java.lang.String) values: [_GrailsInit]
无论Include Init.groovy还是_GrailsInit.groovy都一样。
可是使用的是文档提供的例子。为什么?

最新评论
2 周 3 天之前
2 周 5 天之前
4 周 5 天之前
5 周 2 天之前
5 周 3 天之前
5 周 6 天之前
6 周 4 天之前
11 周 6 天之前
13 周 5 天之前
15 周 3 天之前