Đang chuẩn bị liên kết để tải về tài liệu:
Bắt đầu với IBM Websphere smash - p 16

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

132 Chapter 6 Response Rendering Business Logic Header Header Dynamic Content Nav Footer Dynamic Content Nav Footer Figure 6.8 Updated assembly flow Listing 6.10 /public/quiz/index.gt—Simple Redirect to Business Logic Listing 6.11 /app/scripts/quiz.groovy—Business Logic Controller def go() { if ( request.params.quiz[] == null ) { request.params.page = "home" } else { request.params.page = "quiz" request.params.quiz = getQuizData() } // This would be pulled from DB or config file request.params.nav = [ 'home' : 'Home', 'php' : 'PHP Quiz', 'groovy': 'Groovy Quiz', 'dojo' : 'Dojo Quiz', 'smash' : 'sMash Quiz' ] request.view = "quiz/theme/main.gt" render() } Download from www.wowebook.com Using Views for Rendering 133 def getQuizData() { // Determine quiz, and get questions. return [ 'title': 'PHP Quiz', 'questions': [. | 132 Chapter 6 Response Rendering Figure 6.8 Updated assembly flow Listing 6.10 public quiz index.gt Simple Redirect to Business Logic invokeMethod quiz.groovy go null Listing 6.11 app scripts quiz.groovy Business Logic Controller def go if request.params.quiz null request.params.page home else request.params.page quiz request.params.quiz getQuizData This would be pulled from DB or config file request.params.nav home Home php PHP Quiz groovy Groovy Quiz dojo Dojo Quiz smash sMash Quiz request.view quiz theme main.gt render Download from www.wowebook.com Using Views for Rendering 133 def getQuizData Determine quiz and get questions. return title PHP Quiz questions q A PHP script block looks like a php . php . php . php . Other questions As you can see all of our controller and business logic is contained with the quiz.groovy script. We essentially set our target content page and push a view variable onto the request. Finally we render our theme view template. I won t repeat the code for the theme but it s essentially the page load of HTML and includes our header footer and navigation which also had its business-specific content moved into our controller. The only difference now is we dynamically pull in our target content page as shown in Listing 6.12. The nice thing here is that it would be trivial to modify this to handle either a single or multidimensional array of target pages to include so we can have a simple mash-up environment. Listing 6.12 app views quiz theme main.gt fragment -Include Our Content Page td class content request.view quiz request.params.page .gt render td The last item we should look at is the new quiz.gt view file shown in Listing 6.13. In our controller file we defined a complex quiz data object that we put on the request. This allows our Download from www.wowebook.com 134 Chapter 6 Response Rendering quiz view to be ignorant of the data contents and thus makes it highly reusable. The first page of our PHP quiz can now be seen in Figure 6.9.