1 / 24

Struts2 Plugin Development

Struts2 Plugin Development. - Extending Struts2 Justin Yip. Roadmap. Plugin Architecture Extension points Static resources Tag development. Plugin Architecture.

minor
Download Presentation

Struts2 Plugin Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Struts2 Plugin Development - Extending Struts2 Justin Yip

  2. Roadmap • PluginArchitecture • Extension points • Static resources • Tag development

  3. Plugin Architecture Struts 2 provides a simple plugin architecture so that developers can extend the framework just by adding a JAR to the application's classpath. • Struts2 Plugins are contained in a JAR • Contains classes and configurations • Extend, replace, or add to exsiting Struts framework functionality • The JAR should contain a struts-plugin.xml file

  4. Sample struts-plugin.xml

  5. Roadmap • PluginArchitecture • Extension points • Static resources • Tag development

  6. Struts2 Plugin provides • Packages • Interceptors • Results • Actions • Core component Extensions • Constants

  7. Core component Extension Points

  8. Plugin examples

  9. Json-plugin • Struts2 json插件提供了序列化成为json对象的功能 • 插件定义了一个包 “json-default”,包内定义了一个结果类型“json”,还有一个负责将java对象序列化成json对象的拦截器

  10. Spring-plugin • Extending core component:com.opensymphony.xwork2.ObjectFactory

  11. Config Browser Plugin See an application's configuration at runtime. It is a small struts2 application. Provide actions, freemarker pages and stylesheets.

  12. Static resources Some plugin, UI widgets in particular, need to provide static resource(stylesheets, images, etc…) within plugin archive. With struts2 pluginmechanism, you can package these resources in jar. Static resources are placed under “/static” in plugin jar, and we can refer it in page using “/static” as the path. Assuming “/static/background.jpg” is inside a pluginjar, And we refer it: <@s.url value="/static/background.jpg" var=“img_bg" />

  13. Creating a new Project • Create a new Maven2 project “widgets-accordion” using Archetype: “maven-archetype-quickstart” • Fill out Group Id, Artifact Id, version etc.

  14. Creating a new Project • Change compiler level to 1.5 • Config “maven-compiler-plugin” below: • Update project facts using “mvneclipse:eclipse”

  15. Creating a new Project • Add maven dependency • org.apache.struts struts2-core • org.apache.struts struts2-json-plugin • javax.servletservlet-api • javax.servlet.jspjsp-api • junitjunit

  16. Plugin Entry point • Create a struts2 plugin configuration • declare a bean of type “org.apache.struts2.views.TagLibrary”, named “com.redhat.widget.DemoTagLibrary” Perfix with “rw”

  17. Class Diagram

  18. The class • A custom tag library must be descendant of “org.apache.struts2.views.TagLibrary • Here we support freemarker only • Return an new instance of DemoModel in getFreemarkerModels

  19. The freemarker model accordion.ftl

  20. The AccordionModel • Returns the tag bean in getBean() method

  21. Accordion Tld class for jsp Template selecting Theme selecting

  22. Handling params Extra params from value stack Retrieve param value from tag xxx.ftl

  23. View template accordion.ftl accordion-close.ftl

  24. Test Drive • Install the artifact using “mvn install” • Test this tag in demo project • Test our API : $("#a1").trigger("accordion-foldAll")

More Related