Extending Struts(1)

1,097 views
986 views

Published on

Struts version 1 plugin extension

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,097
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
28
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Extending Struts(1)

  1. 1. Extending Struts Prepared by: Ramez Hassan
  2. 2. Agenda <ul><li>Struts Overview : </li></ul><ul><ul><li>Basic review on struts framework. </li></ul></ul><ul><ul><li>Stating struts main objects. </li></ul></ul><ul><li>What is a plug-in? </li></ul><ul><ul><li>ModuleConfig story. </li></ul></ul><ul><li>Tiles plug-in: </li></ul><ul><ul><li>Default design procedure. </li></ul></ul><ul><ul><li>Tiles with struts. </li></ul></ul>
  3. 3. Struts Overview <ul><li>Struts is a framework that is built on MVC 2 architectural pattern. </li></ul><ul><li>Struts Flow review. </li></ul><ul><li>Struts gives extension capabilities to each step. </li></ul>
  4. 4. Struts Overview <ul><li>Struts Main Objects: </li></ul><ul><ul><li>ActionServlet. </li></ul></ul><ul><ul><li>RequestProcessor. </li></ul></ul><ul><ul><li>ModuleConfig. </li></ul></ul><ul><ul><li>ActionClass. </li></ul></ul><ul><ul><li>ActionForm. </li></ul></ul><ul><ul><li>JSP view. </li></ul></ul>
  5. 5. What is a plug-in ? <ul><li>A plug-in is a configuration wrapper for a module-specific resource or service that needs to be notified about application startup and shutdown events. </li></ul>
  6. 6. What is a plug-in ? <ul><li>How to plug in a struts plug-in ? </li></ul>
  7. 7. What is a plug-in ? <ul><li>How to write a plug-in ? </li></ul>
  8. 8. What is a plug-in ? <ul><li>What is ModuleConfig ? </li></ul>
  9. 9. So, A Plug-in is … <ul><li>A useful feature in struts framework that facilitate: </li></ul><ul><ul><li>Dynamically wrap any resource of struts framework, e.g. RequestProcessor. </li></ul></ul><ul><ul><li>Initialize any business component for the application, e.g. Hibernate. </li></ul></ul>
  10. 10. Tiles Plug-in <ul><li>Applying html layout procedures: </li></ul><ul><ul><li>Default Design procedure was to copy and paste layout to every new page. </li></ul></ul><ul><ul><li>Altering in design could lead to a resources leak, even though it’s a periodical procedure for any web application. </li></ul></ul>
  11. 11. Tiles Plug-in <ul><li>Applying html layout procedures (cont.): </li></ul><ul><ul><li><jsp:include> allows you to include either a static or dynamic file in a JSP file {every page will use jsp:include}. </li></ul></ul><ul><ul><ul><li>The problem: when the architecture changes even a small td in a table will lead to alterations in every page in the site. </li></ul></ul></ul>
  12. 12. Tiles Plug-in <ul><li>Tiles Solution : </li></ul><ul><ul><li>Applying same mechanism of <jsp:include /> but with defining the layout it self in a separate page. </li></ul></ul><ul><ul><li>The components in this case will be: </li></ul></ul>
  13. 13. Tiles Plug-in <ul><li>Tiles Solution (cont.): </li></ul><ul><ul><li>Each new page in this case will require defining the following : </li></ul></ul><ul><ul><ul><li>Page body (which the part that changes frequently, 0 to n pages). </li></ul></ul></ul><ul><ul><ul><li>Page layout (The layout that will be attached when displaying the page). </li></ul></ul></ul><ul><ul><ul><li>Any dynamic or static content will be referenced in the layout, e.g. header , footer and/or menu. </li></ul></ul></ul><ul><ul><li>This solution made it much better in changing layout but a little bit difficult in pages maintenance. </li></ul></ul>
  14. 14. Tiles Plug-in <ul><li>Struts Tiles plug-in Solution: </li></ul><ul><ul><li>The same as tile solution except adding XML capabilities in definition and Objects relation as well. </li></ul></ul>
  15. 15. Tiles Plug-in <ul><li>Struts Tiles plug-in Solution (cont.): </li></ul><ul><ul><li>Struts Tiles demo. </li></ul></ul>
  16. 16. Tiles Plug-in <ul><li>Struts Tiles demo (cont.): </li></ul><ul><ul><li>XML Configurations:- </li></ul></ul>
  17. 17. Tiles Plug-in <ul><li>Struts Tiles demo (cont.): </li></ul><ul><ul><li>Static Objects </li></ul></ul><ul><ul><ul><li>tiles_static/header.jsp </li></ul></ul></ul><ul><ul><ul><li>tiles_static/menu.jsp </li></ul></ul></ul><ul><ul><ul><li>tiles_static/footer.jsp </li></ul></ul></ul>
  18. 18. Tiles Plug-in <ul><li>Struts Tiles demo (cont.): </li></ul><ul><ul><li>Layout Definition Page: </li></ul></ul><ul><ul><ul><li>tiles_layout/layout_small.jsp </li></ul></ul></ul>
  19. 19. Tiles Plug-in <ul><li>Struts Tiles demo (cont.): </li></ul><ul><ul><li>Adding tiles into layout using struts-tiles.tld: </li></ul></ul>
  20. 20. Tiles Plug-in <ul><li>Struts Tiles demo (cont.): </li></ul><ul><ul><li>Finally the page to display :- </li></ul></ul><ul><ul><li>I can write my code in the page /demos/myPage.jsp and don’t worry about layout any more. </li></ul></ul>
  21. 21. Tiles Plug-in <ul><li>Struts Tiles demo (cont.): </li></ul><ul><ul><li>How can struts actions interact with tile page: </li></ul></ul>
  22. 22. Tiles Plug-in <ul><li>Configurations needed : </li></ul>
  23. 23. Tiles Plug-in <ul><li>How does tiles plug-in work…? </li></ul><ul><ul><li>Replaces RequestProcessor in startup with TilesRequestProcessor. </li></ul></ul><ul><ul><li>TilesRequestProcessor class overrides processForwardConfig() to handle any navigation to any tiles definition. </li></ul></ul><ul><ul><li>In processing a definition, all pages is included using doForward() doInclude() or of RequestProcessor which uses methods of RequestDispatcher. </li></ul></ul>
  24. 24. Tiles Plug-in <ul><li>Tiles attributes: </li></ul><ul><ul><li>TileScope is a ComponentContext for tiles components (pages). </li></ul></ul><ul><ul><li><tile:useAttribute name=“” id=“” scope=“”/> is used to move attributes from tiles scope to request scope. </li></ul></ul>
  25. 25. Tiles Plug-in <ul><li>Tiles attributes (cont.): </li></ul><ul><ul><li>< put:list name=“demoList”> </li></ul></ul><ul><ul><ul><li>< item value=“link1&quot; link=&quot;/li1.do&quot; /> </li></ul></ul></ul><ul><ul><ul><li>< item value=“link2&quot; link=&quot;/li2.do&quot; /> </li></ul></ul></ul><ul><ul><ul><li>< item value=“link2&quot; link=&quot;/li3.do&quot; /> </li></ul></ul></ul><ul><ul><li></ put:list > </li></ul></ul><ul><ul><li>Values can be retrieved and used as List in any scope. </li></ul></ul>
  26. 26. Questions ?
  27. 27. Thank You

×