2012-12-02 2 views
2

내 필터의보기 폴더 안에 .GSP보기를 렌더링하려고합니다. 다음 코드는 이것을 보여줍니다 :필터의 렌더링 GSP가 작동하지 않습니다.

def filters = { 
    all(controller:'*', action:'*') { 

     afterView = { Exception e -> 

     if (controllerName) { 
      //some code here 

      if (annotation!=null) { 
       switch(response.format){ 

        case 'all': 
        if(!response.containsHeader("AC_MSG")|| !response.containsHeader("AC_STATUS")){ 

         render(view: "/internalerror", model: [controller: controllerName,action:currentAction, 
           message:"Response doesn't contain required headers AC_MSG or AC_STATUS. Either add the required headers or use json format.", 
           example:"Add the following response headers: AC_MSG:response message , AC_STATUS: false or true" 
         ]) 
         return false 
        } 

        break 
        default: 
        render status: 406 
        break 
       } 
      } 
     } 
     } 
    } 
} 

문제는 코드가 실행 되더라도이 페이지가 렌더링되지 않는다는 것입니다. 이 페이지는 뷰 디렉토리에 직접 있습니다. 내가 뭘 잘못 했니?

감사합니다,

답변

2

필자는 필터가 gsp를 렌더링 할 수 있다고 생각하지 않지만 컨트롤러는이를 수행 할 수 있습니다.

filters는 기본적으로 페이지를 렌더링하는 컨트롤러 내부 작업을 생성하고, 필터는 작업에 리디렉션

당신이 원하는 무엇의 완벽한 예는 문서에서 사용할 수 있습니다.

경우는 '모든'

    if(!response.containsHeader("AC_MSG")|| !response.containsHeader("AC_STATUS")) { 

        redirect(controller: "someController", action:"someAction") 
        return false 
       } 
0

ErrorController.groovy을 확인하고이 렌더링보기로 해, params와 동작을 구현합니다. 필터에서 리디렉션 만 사용하십시오. 'return false'문도 제거하십시오.

+0

당신은 왜 리디렉션 만 사용하여 설명 할 수 있을까요? 거짓을 돌려 보내지 않는 이유는 무엇입니까? –

관련 문제