Содержание
- 2. Who am I? Mike Cannon-Brookes OpenSymphony Project - www.opensymphony.com Atlassian Software Systems - www.atlassian.com CONFLUENCE Thought
- 3. Agenda The Problem What is SiteMesh? A Simple Example How does it work? Advanced techniques Decorator
- 4. WEB-APP DECORATION THE PROBLEM
- 5. Your form looks like this… 20 lines of simple focused HTML Simple to maintain Developer can
- 6. Your boss wants it to look like… 300 lines of complex HTML Developers must find 20
- 7. The Decoration Problem Separating content & presentation is hard! Every web application needs to do it.
- 8. Decoration Example
- 9. Decoration Example Header Navigation Information Downloads Login News Search
- 10. Decoration Examples Typical decorations: Headers Footers Navigation elements People forget: Panels within a single page Agent
- 11. SOLUTIONS TYPICAL
- 12. Solutions Copy & paste VERY BAD: Fire your developer. JSP includes BAD: Fragile, strongly coupled and
- 13. SITEMESH? WHAT IS
- 14. SiteMesh is… Open Source J2EE page layout and decoration engine www.opensymphony.com/sitemesh Interpretation of GoF decorator pattern
- 15. Web Container Where does it fit? Implemented as a Servlet 2.3 request filter Requires Servlet 2.3
- 16. Web Container Where does it fit? Request with SiteMesh filter deployed: Web App 2. Generate page
- 17. EXAMPLE A SIMPLE
- 18. Simple Example Install SiteMesh Write a simple JSP page Write a JSP decorator Adds a heading
- 19. Installation Careful - it’s complicated… Copy sitemesh-2.x.jar to the WEB-INF/lib/ directory of your web-app Install and
- 20. Write Simple Page About JavaBlogs JavaBlogs aggregates the blogs of Java bloggers.
- 21. Write simple decorator java.blogs - "> Section: MyDecorator.jsp
- 22. Map decorator Let’s simply map this to decorator to all URLs. Basic URL mapping is done
- 23. The Result java.blogs - About JavaBlogs About JavaBlogs Section: About JavaBlogs aggregates the blogs of Java
- 24. CONFUSED! I’M STILL
- 25. 4 ways to think about SiteMesh Decoupling is a good thing SiteMesh decouples page decoration Agile,
- 26. SiteMesh is… clean. Clean, logical separation of content vs presentation Content - JSP file Decorator -
- 27. SiteMesh is… friendly! Decorators written in your favourite templating language Usually JSP but also Velocity, FreeMarker.
- 28. What is a decorator? Decorator decides where the parsed fields are inserted into the final page
- 29. Usage By Large App ATLASSIAN JIRA is a large web app we build. A good example
- 30. IT WORK?! HOW DOES
- 31. How it works… Result (HTML) 1. 4. Content (HTML fragment) Content Source (JSP, Perl, PHP, HTML
- 32. 1. Server renders HTML Keep your HTML simple, without any decoration. Example rendered HTML: About JavaBlogs
- 33. 2. SiteMesh parses HTML Turns your HTML into a map of fields Title and body extracted
- 34. 3. SiteMesh selects decorator Effectively uses a sequence of rules (DecoratorMapper objects) to select a decorator
- 35. 4. Merge content & decorator Resulting code is plain HTML again Example result: java.blogs - About
- 36. TECHNIQUES ADVANCED
- 37. How is the decorator chosen? A stack of DecoratorMappers are consulted in sequence to find a
- 38. Packaged Mappers SiteMesh Page Frameset Printable Language Client OS Config User Agent Parameter Robot — Uses
- 39. ConfigDecoratorMapper Most frequently used mapper, matches on URL patterns Example of configuration (decorators.xml): /* /admin.jsp /*/admin/*
- 40. Inline decorators SiteMesh can also decorate ‘panels’ within a web page Called ‘inline decorators’ Useful for
- 41. Example Inline decorator Note: looks just like a normal decorator Only no etc Defined in decorators.xml
- 42. Inline Decorator Usage ... This site is not legally binding in any way. All rights reserved.
- 43. Inline Decorator Screenshot
- 44. Inline Components Inline decorators can create complex ‘view components’ Useful for coarse-grained view components We use
- 45. jiraform.jsp PARAMETERS: (all are optional) action - the URI to submit this form too submitName -
- 46. JIRA form screenshot
- 47. JIRA form decorator " method=" " name=" " onsubmit=" " ENCTYPE="multipart/form-data" > . . . (draw
- 48. JIRA form usage CreateIssue.jspa >> list="allowedProjects" listKey="'long('id')'” listValue="'string('name')'" >
- 49. Content Blocks For passing parameters and HTML directly to the decorator Warning: increases coupling! Useful where
- 50. Content Block Example Anything inside a tag is a content block. SiteMesh will strip these blocks
- 51. Content Block Decorator ... #if ($page.getProperty("page.breadcrumbs")) Location: $page.getProperty("page.breadcrumbs") #end ... mydecorator.vmd We display breadcrumb block only
- 52. Tips & Tricks Group decorators into /decorators Helps developers differentiate presentation from content Don’t be afraid
- 54. Скачать презентацию