2017-09-28 11 views
0

아래에 표시된 내 응용 프로그램에서 하나의 사용자 정의 태그 lib 클래스를 작성했습니다.Grails 3 : 프런트 엔드에서 문자열로 표시되는 사용자 정의 태그 출력

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

      attrs.from = myservice.invokeMethod(servMethod,null); 

      out << g.select(attrs) 
     }catch(Exception e){ 
      println("Exception in CustomTagLib in method selectList:"+e) 
     } 
    } 
} 

그러나 출력은 다음과 같이 문자열로 표시됩니다. enter image description here

이 문제를 해결하기위한 제안 사항을 알려주십시오.

답변

1

템플릿에 렌더링 코드를 추가해보세요. 예 :

def from = myservice.invokeMethod(servMethod,null); 

out << render(template: "/templates/dropdown", 
     model: [from: from]) 

그런 /views/templates/_dropdown.gsp

<g:select from="${from}" /> 

에서 당신은 물론 모델에 더 인수를 전달할 수 있습니다.