2010-05-06 6 views

답변

11

구성한 taglib을 얻을 수는 있지만 대부분 웹 요청 컨텍스트에서 실행될 것으로 예상된다. 이 문제를 해결하려면 모의 요청을 바인딩 할 수 있습니다.

요청의 로캘을 설정하여 다른 언어의 메시지를 가져올 수도 있습니다. 예 : 당신은 실행하여 응용 프로그램의 모든 태그 라이브러리의 목록을 얻을 수 있습니다

import org.codehaus.groovy.grails.plugins.web.taglib.ValidationTagLib 

// Getting the class name to reduce horizontal 
// scrolling in StackOverflow 
def g = ctx.getBean(ValidationTagLib.class.getName()) 

g.message(code: 'default.button.delete.confirm.message'); 

이 우리가 웹 요청을 조롱하지 않는 경우에도 쉽게 @Burt console plugin를 사용

import grails.util.GrailsWebUtil 

def webRequest = GrailsWebUtil.bindMockWebRequest(ctx) 
webRequest.currentRequest.addPreferredLocale(Locale.GERMANY) 

def g = ctx.getBean('org.codehaus.groovy.grails.plugins.web.taglib.ValidationTagLib') 
String message = g.message(code: 'default.button.delete.confirm.message') 
3

... 이 코드는 콘솔에 있습니다 ...

// prints a bean name per line. 
ctx.getBeanNamesForType(Object).findAll { 
    it =~ /.*TagLib$/ 
} .sort() {println it} 

// add false to prevent console printing the map out 
false 
관련 문제