2017-09-28 15 views
0

커스텀 태그 라이브러리 내의 애플리케이션 컨텍스트로부터 서비스 빈을 얻고 싶다. 서비스 이름은 사용자 정의 태그 속성에서 가져옵니다.Grails 3의 커스텀 태그 라이브러리 클래스에서 서비스 빈을 얻는 방법

이것은 이전에 사용한 코드입니다.

class CustomTagLib { 
    static defaultEncodeAs = [taglib:'html'] 
    //static encodeAsForTags = [tagName: [taglib:'html'], otherTagName: [taglib:'none']] 
    def selectList = { attrs -> 
     try{ 
      String servName=attrs.service 
      String servMethod=attrs.method 
      ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(session.getServletContext()) 
      def myservice=ctx."${servName}" 

      attrs.from = myservice.invokeMethod(servMethod,null); 
      out << g.select(attrs) 
     }catch(Exception e){ 
      println("Exception in CustomTagLib in method selectList:"+e) 
     } 
    } 
} 

이 코드는 Grails의 2.3 버전을 나에게 일을한다하지만 버전 3 에 대한 해결책을 찾아 도와주세요.

답변

0

는 다음과 같은 시도 : servName는 나머지

+0

작업 소문자 첫 글자 & 낙타 케이스와 서비스 이름이됩니다

import grails.util.Holders def myservice = Holders.getApplicationContext().getBean(servName) 

, 난 문자 사건에 대해 잊어 버렸습니다. 이제는 두 가지 모두 작동하지만 태그는 프론트 엔드에'