27
Extending Struts Prepared by: Ramez Hassan

Extending Struts(1)

  • Upload
    ramooza

  • View
    21

  • Download
    1

Embed Size (px)

DESCRIPTION

Struts version 1 plugin extension

Citation preview

Page 1: Extending Struts(1)

Extending StrutsPrepared by:

Ramez Hassan

Page 2: Extending Struts(1)

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.

Page 3: Extending Struts(1)

Struts Overview• Struts is a framework that is built

on MVC 2 architectural pattern.• Struts Flow review.• Struts gives extension capabilities

to each step.

Page 4: Extending Struts(1)

Struts Overview• Struts Main Objects:

– ActionServlet.– RequestProcessor.– ModuleConfig.– ActionClass.– ActionForm.– JSP view.

Page 5: Extending Struts(1)

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.

Page 6: Extending Struts(1)

What is a plug-in ?• How to plug in a struts plug-in ?

Page 7: Extending Struts(1)

What is a plug-in ?• How to write a plug-in ?

Page 8: Extending Struts(1)

What is a plug-in ?• What is ModuleConfig ?

Page 9: Extending Struts(1)

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.

Page 10: Extending Struts(1)

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.

Page 11: Extending Struts(1)

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.

Page 12: Extending Struts(1)

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:

Page 13: Extending Struts(1)

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.

Page 14: Extending Struts(1)

Tiles Plug-in• Struts Tiles plug-in Solution:

– The same as tile solution except adding XML capabilities in definition and Objects relation as well.

Page 15: Extending Struts(1)

Tiles Plug-in• Struts Tiles plug-in Solution (cont.):

– Struts Tiles demo.

Page 16: Extending Struts(1)

Tiles Plug-in• Struts Tiles demo (cont.):

– XML Configurations:-

Page 17: Extending Struts(1)

Tiles Plug-in• Struts Tiles demo (cont.):

– Static Objects• tiles_static/header.jsp

• tiles_static/menu.jsp

• tiles_static/footer.jsp

Page 18: Extending Struts(1)

Tiles Plug-in• Struts Tiles demo (cont.):

– Layout Definition Page:• tiles_layout/layout_small.jsp

Page 19: Extending Struts(1)

Tiles Plug-in• Struts Tiles demo (cont.):

– Adding tiles into layout using struts-tiles.tld:

Page 20: Extending Struts(1)

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.

Page 21: Extending Struts(1)

Tiles Plug-in• Struts Tiles demo (cont.):

– How can struts actions interact with tile page:

Page 22: Extending Struts(1)

Tiles Plug-in• Configurations needed :

Page 23: Extending Struts(1)

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.

Page 24: Extending Struts(1)

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.

Page 25: Extending Struts(1)

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.

Page 26: Extending Struts(1)

Questions

Page 27: Extending Struts(1)

Thank You