How to set onSuccess event listener for Grails

Grails inherently supports ajax function, such as remoteFunction, remoteLink, etc.

But do you know how to set onSuccess event listener appropriately?

Let me tell you :)

<input type=”text” id=”name” name=”name” value=”"/>
<input type=”button” name=”checkbizname” value=”Chek whether this name already exists” onclick=”${remoteFunction(controller:’mycontroller’,action:’isNameExists’,onSuccess:’popwin(o)’, params:’\'name=\’ + document.getElementById(\’name\’).value’)}”/>

In the above code, when ajax request is handled and get response from server, onSuccess event listener will be invoked.

Note:

  1. popwin(o) should contain argument ‘o’, as ‘o’ is defined in the code generated by this GSP. You can find this argument via firebug. {success: function(o){popwin(o);}, failure: function(o){}}
  2. Another important thing is, you should define this function popwin(o) in head section in GSP. It seems a bug that funtions defined between head and body will not be invoked at all.
By javafuns on May 21, 2009 at 22:11 · Views: 2,274 · Permalink · RSS · Leave a comment
Categorized in: Scripts · Tagged with: , , ,

HIBERNATE-为DB2指定默认schema

hibernate 有一个属性hibernate.default_schema,设置了该属性后,hibernate将使用该schema.

例如:在hibernate.cfg.xml

<property name="default_schema">MYSCHEMA</property>

另外,如果你使用的是 jdbc 直接访问数据库,那么可以在 url 中加上 currentSchema=MYSCHEMA,例如:

<Resource name="jdbc/UddiDatabase" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="50" maxWait="10000"
username="db2admin" password="db2admin"
driverClassName="com.ibm.db2.jcc.DB2Driver"
url="jdbc:db2://192.168.56.101:50000/UDDI:traceLevel=3;driverType=4;currentSchema=MYSCHEMA;"/>

如果你遇到了有关schema的问题,那么不妨将这两种方案都尝试一下.

By javafuns on May 15, 2009 at 16:46 · Views: 2,220 · Permalink · RSS · Leave a comment
Categorized in: Database, Java · Tagged with: , , , , ,

How to configure Tomcat to support remote debugging

How do I configure Tomcat to support remote debugging?

The short answer is to add the following options when the JVM is started: -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n There are a number of ways you can do this depending on how you normally start Tomcat:

The port does not need to be set to 8000, it may be any value appropriate for your system.

Whilst this is very useful in development it should not be used in production because of both security and performance implications.

Copied from: http://wiki.apache.org/tomcat/FAQ/Developing#Q1

By javafuns on May 13, 2009 at 17:24 · Views: 1,662 · Permalink · RSS · Leave a comment
Categorized in: Java · Tagged with: ,

How to install libstdc++.so.5 for Ubuntu

Today when I tried to run our applications, I was told that there is a necessary library libstdc++.so.5 missing.

Now, I give the programmers who also faces the same problem a solution:

sudo apt-get install libstdc++5

By javafuns on May 13, 2009 at 09:25 · Views: 1,711 · Permalink · RSS · Leave a comment
Categorized in: Java, Operation Systems · Tagged with: , ,

Groovy 学习笔记 (二)

5. 方法调用: 方法调用时, 括号是可选的. 例如: print ‘hello, world’

6. 方法返回值: 默认最后一句就是方法的返回值, 也就是说, 最后一句的return语句是可有可无的. 当然, 如果在方法中间需要return值, 还是要写 return 语句才行.

7. 闭包(closure): 闭包可以访问与闭包定义在同一scope的变量. 例如:

def name = “” //initialize variable

def printName = { println “The string in the name variable is ” + name } //define method

name = “Youssef” //set string Youssef in variable name

printName() //result: The string in the name variable is Youssef

如果不在同一scope, 那么需要给闭包指明参数, 参数与闭包的body部分用 -> 符号分隔. 如果只有一个参数, 则该参数可不必明确写出来, 默认用 it 作为该参数的名称.

def name = “” //initialize variable

def printName = { println “The string in the name variable is ” + it } //define method

name = “Youssef” //set string Youssef in variable name

printName(name) //result: The string in the name variable is Youssef

8. 异常处理: 不是强制性的

9. methodMissing 与 propertyMissing 方法:

10. categories:

class StringCategory {
static String lower(String string) {
return string.toLowerCase()
}
}


use (StringCategory) {
assert "test" == "TeSt".lower()
}

By javafuns on May 4, 2009 at 17:47 · Views: 3,421 · Permalink · RSS · Leave a comment
Categorized in: Scripts · Tagged with: , , ,

Grails RichUI plugin

Rich UI 是一个 AJAx 插件, 可以干很多事情:

我就用它做了一个 rating 功能, 哈哈, 真是超级简单, 超级方便.  在下面的链接里, 有详细的使用说明, 只要你的英语不是很烂, 就很容易搞明白如何使用.

具体地址: RichUI Plugin

By javafuns on April 28, 2009 at 21:24 · Views: 2,362 · Permalink · RSS · Leave a comment
Categorized in: Scripts · Tagged with: , , , ,

Groovy 学习笔记 (一)

1. 关于字符串:

简单字符串可以用单引号和双引号, 但如果使用GString, 则必须使用双引号. 比如 “$foo, hello world”

多行字符串则可以使用 “”" (3个双引号), 例如:

def text = “”"\
hello there ${name}
how are you today?
“”"
如果对这个text进行输出,会发现输出是按原样式输出的,即换行符也输出. 这在处理类似 HTML 代码时时特别有用的.
另外, 可以使用 /…/ 来定义字符串, 如: def basename = /[Strings and GString^\/]+$/
在这种情况下, 只需对 / 进行转义: \/; 但如下定义是不合法的:def x = //, 可以这么写: def x = /${}/

2.字符串操作: Read more »

By javafuns on April 27, 2009 at 15:17 · Views: 2,124 · Permalink · RSS · 2 Comments
Categorized in: Scripts · Tagged with: ,

Grails – JCaptcha Plugin usage

JCaptcha

JCaptcha 是一个开源 (LGPL) captcha 解决方案. JCaptcha 提供了图片的和音频的方式, 同时只要你愿意, 也可以进行扩展从而提供其它不同的方式.

支持版本

||Version||Minimum Grails Version||Notes|| | 0.1 | 0.6 | | | 0.2 | 1.0-RC1 | |

Plugin

Grails JCaptcha plugin 提供了一种简易方式去定义 Captchas, 显示和验证.

安装

该插件存放于官方库, 所以可以通过如下方式进行安装

grails install-plugin jcaptcha

用法

定义 Captchas

Captchas 定义在 grails-app/conf/Config.groovy 文件中.

log4j {
/* log4j config */
}

jcaptchas { captcha1 = … captcha2 = … }

每个 jcaptcha.* 条目必须是一个 CaptchaService 的实例, 负责生成验证方式和进行验证.
一些例子 Captchas …

import java.awt.Font
import java.awt.Color

import com.octo.captcha.service.multitype.GenericManageableCaptchaService
import com.octo.captcha.engine.GenericCaptchaEngine
import com.octo.captcha.image.gimpy.GimpyFactory
import com.octo.captcha.component.word.wordgenerator.RandomWordGenerator
import com.octo.captcha.component.image.wordtoimage.ComposedWordToImage
import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator
import com.octo.captcha.component.image.backgroundgenerator.GradientBackgroundGenerator
import com.octo.captcha.component.image.color.SingleColorGenerator
import com.octo.captcha.component.image.textpaster.NonLinearTextPaster

import com.octo.captcha.service.sound.DefaultManageableSoundCaptchaService

jcaptchas {
  imageCaptcha = new GenericManageableCaptchaService(
    new GenericCaptchaEngine(
      new GimpyFactory(
        new RandomWordGenerator("abcdefghijklmnopqrstuvwxyz1234567890"),
        new ComposedWordToImage(new RandomFontGenerator(
           20, // min font size
           30, // max font size
           [new Font("Arial", 0, 10)] as Font[] ),
        new GradientBackgroundGenerator(
           140, // width
           35, // height
           new SingleColorGenerator(new Color(0, 60, 0)),
           new SingleColorGenerator(new Color(20, 20, 20))),
        new NonLinearTextPaster(6, // minimal length of text
           6, // maximal length of text
           new Color(0, 255, 0) )
      )
    )
  ),
  180, // minGuarantedStorageDelayInSeconds
  180000 // maxCaptchaStoreSize
)

captcha 服务的构造/配置由 JCaptcha 自己来完成, 所以如感兴趣请参考 JCaptcha documentation .

JCaptcha Controller

该插件安装了一个 controller 叫做 ‘JCaptchaController’. 它的功能是 render captcha 的表现. 当前支持 2 种表现格式: jpeg 和 wav.
controller 支持像 {{jcaptcha/jpeg/<captchaname>}} 和 {{jcaptcha/wav/<captchaname>}} 这样的 URIs, 它们会将二进制输出写入输出流中.

一定要确保你没有将一个图片 captchas 表现(render)为音频, 反之亦然. 如果你尝试这么去干, 那么你将会得到一个 IllegalArgumentException.

JCaptcha Tags

该插件分别提供了两种用于 jpeg 和 wav 的标签.
<jcaptcha:jpeg name="<captchaname>" height="Xpx" width="Xpx" /> // results in an img tag
<jcaptcha:wav name="<captchaname>" autostart="0" /> // results in an embed tag

你也可以传递底层HTML标签所能够接受的其它属性给这 2 个标签.

JCaptcha 服务

JCaptchaService 类负责获得在你的 config 中定义的 CaptchaService 实例. 它也用于进行验证.

class ExampleController
{
  def jcaptchaService

  def index = {
    if (jcaptchaService.validateResponse("captchaName", session.id, params.captchaResponse)) {
      /* User entered response correctly
    } else {
      /* User got it wrong, OR THEY ARE A BOT Let's get em.
    }
  }
}

需留意的是, 你必须要传递 {{session.id}} 给 {{validateResponse}}. 这是因为 captcha 服务需要将用户所提交的验证码与之前生成的验证码进行匹配从而检查是否正确. 它们之间的关键点就是 {{session.id}}.

另外, captchaName 是你在 config 中所定义的 capatcha 的名字; params.captchaResponse 的 captchaResponse 就是用户需要输入的 input 的 name 属性值.

例子程序

这是完整的使用到了 JCaptcha 插件的 例子程序.

By javafuns on April 26, 2009 at 20:50 · Views: 1,168 · Permalink · RSS · Leave a comment
Categorized in: Scripts · Tagged with: , ,
  • Highest Rated

  • My PicasaPhotos

    IMG_0519.JPG

    IMG_0558.JPG

    IMG_0546.JPG

  • RSS My del.icio.us

  • My RSS