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