2012-03-01 65 views
0

看看这是我的问题:我已更新到Grails 2.0.1,现在我必须创建一个QR码。我已经安装了qrcode插件0.1,但它不工作。我正在使用标签:qrcode-0.1与Grails 2.0.1

<qrcode:image text="${createPromoInstance.id}" /> 

但它似乎什么也没做。我调试谷歌浏览器,我意识到,在“元素”选项卡中,标签正在更改为<call></call> 昨天我问这个,有人说我的插件有一些错误,不适用于Grails 2.0。 1,他给了我一些关于我能做些什么的建议。 例如,我editted的QRController这样的:

class QrcodeController{ 
    QRCodeRenderer qrcodeRenderer = new QRCodeRenderer() 

    def index = { 
     qrcodeRenderer.renderPng(response, request.getHeader("REFERER"), 300i) 
    } //It doesn't have any change 

    def url = { 
     String uri = params.u 
     String size = getSize(params) 
     qrcodeRenderer.renderPng(response, uri, size.toInteger().intValue()) 
    } //it doesn't have any change 

    protected String getSize(Map params){ 
     String size = params.s 
     if(!size || size.matches(/\D\)) {size = "128"} 
     return size 
    } //I have added the "protected word" 

    def text = { 
     String content = params.t //it used to be params.text 
     String size = getSize(params) 
     qrcodeRenderer.renderPng(response, content, size.toInteger().intValue()) 
    } 
} 

,他说如果我做这些改变,将工作,但没有,它没有!我试图在空gsp中呈现代码,以便像这样尝试:

<%page contentType="text/html;charset=UTF-8" %> 
<html> 
<head> 
    <title><title> 
<head> 
<body> 
    <div> 
     <qrcode:image text="${createPromoInstance.id} /> 
    </div> 
</body> 
</html> 

据我了解,它应该可以工作,但事实并非如此。有谁知道我做错了什么?我必须做其他事情才能得到QR码? 感谢您的帮助! Jonatan! Jonatan!

回答

0

我找到了答案......如果有人需要,我会把它留在这里。 为了得到这个工作,你需要做一些改变,如我以前写的。

protected String getSize(Map params{ //it used to be String getSize(Map params) 
    String size = params.s 
    if (!size || size.matches(\/D/) {size = "128"} 
    return size 
} 

def text = { 
    String content = params.t //it used to be params.text 
    String size = getSize(params) 
    qrcodeRenderer.renderPng(response, content, size.toInteger().intValue()) 
} 

但这并不是一切,你必须改变在BuildConfig别的东西,像这样:

//find the plugin call 
plugins{ 
    //this is how my plugins call looks like, here you might see the calls of the plugins you have installed 
    runtime: ":hibernate:$grailsVersion" 
    runtime: ":jquery:1.7.1" 
    runtime: ":resources:1.1.6" 
    //and you gotta add this 
    compile: ":qrcode:0.1" 
    /*. 
    . 
    .*/ 
    build: ":tomcat:$grailsVersion" 
} 

然后,你必须去插件标签库“QRCodeTagLib “并替换为:

def image = {attrs-> 
    def size = attrs.height?:attrs.width 
    String text = attrs.text 
    String src = createLink(controller:'qrcode',action:'text',params:[t:text,s:size]) 
    //it used to be like this 
    /*def mkp = new groovy.xml.MarkupBuilder(out) 
     mkp{ 
      img(alt:url, src:src) 
     } 
    */ 
    //and now it looks like this 
    out <<"<img alt=\"${text}\" src=\"${src}\"/>" 
} 

就是这样,你的QR码将被呈现!

希望它对任何人都有用! Jonatan !! PD:这个代码的功劳不是我的,有人帮我在grails脸书页上!非常感谢Ingo。 :) 啊!其他的事情......他还说在引导的东西,但它并没有为我工作,在引导他把:

QRCode m = new QRCode() 
m.save() 

尝试,让我知道,如果你是这样的! :)