• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Struts Tiles Tutorial

 
Author
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using Struts?
Have you started using Tiles yet?
Why not?
Master the Tiles Framework with this tutorial....
URL: http://www.arc-mind.com/downloads.htm#TilesTutorial
The Tiles framework makes creating reusable pages and visual components easier. Developers can build Web applications by assembling reusable tiles. You can use tiles as templates or as visual components.
In some respects, the tile layout is like a display function. First you pass tile layout parameters to use. The parameters can be simple strings, beans, or tiles. The parameters become attributes to the tile and get stored in the tile's tile scope. For its part, the tile scope resembles page scope, and is less general than request scope. The tile scope lets the tile's user pass arguments (called attributes) to the tile.
Definitions let you define default parameters for tiles. Definitions can be defined in JSP or XML. Definitions can extend other definitions similarly to how a class can extend another class. Moreover, definitions can override parts of the definition it is extending.
The Tiles framework includes its own RequestProcessor to handle tile layouts as ActionForwards. Thus you can forward to a tile definition instead of a JSP if you install the Tiles plug-in.
If you are using Struts but not Tiles, then you are not fully benefiting from Struts and likely repeat yourself unnecessarily. The Tiles framework makes creating reusable site layouts and visual components feasible.

In this tutorial you will cover the following:

The Tiles framework and architecture
How to build and use a tile layout as a site template
How to use tile definitions both in XML and JSP
How to move objects in and out of tile scope
How to work with attributes lists
How to nest tiles
How to build and use tile layouts as small visual components
How to subclass a definition
How to create a controller for a tile
How to use a tile as an ActionForward
http://www.arc-mind.com/downloads.htm#TilesTutorialStruts Tiles Tutorial
 
Rick Hightower
Author
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay so really... what did you think? Good? Bad? Ugly?
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your information..That's very useful for my job...
thank again..!!
 
Rick Hightower
Author
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome!
 
Rick Hightower
Author
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Has anyone else read this?
What did you think?
Huh?
 
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am busy for some days. I will find time to read them next week.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi RIck,
What a coincidence..I was just looking over your tutorial as I was planning to use it. Well it actually came back on the top when I searched for "tiles framework" on Google . I briefly glanced over it and found it quite nice. I would probably try out the samples tomorrow. Thanks for the nice tutorial.
[ January 15, 2004: Message edited by: Nurat Lamos ]
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rick,
I'm looking forward to checking out your tutorial.
Did you know that Tiles can be used with Spring's web MVC tier ?
With the ResourceBundleViewResolver class, you can mix the view using different view technologies. ResourceBundleViewResolver uses a properties file to resolve view names to classes.
Thanks
 
Rick Hightower
Author
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ken the more I learn about Spring the better I like it. I've already started to dig in.
A friend of mine is writing a Spring book. I will be one of the technical reviewers for the Spring book.
I see a lot of Spring in my future.
Right now I am digging into AppFuse, JSF and Spring. I have two new projects that I am working on. (One starts Monday). (One Starts two months from Monday).
I plan on using Struts, AppFuse, Hibernate and Spring.
In the past, I have used Struts and Hibernate.
At this point, I wont use Spring for things Struts can do. Mainly because I know Struts really well (learning curve and such). I plan on using Spring behind Struts (more for the model tier if you will).
Perhaps in the future, I will use Spring for some of things Struts can do.
I have a lot of experience invested in Struts.
 
Ken Krebs
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I see a lot of Spring in my future.


Spring works well with Hibernate. The Petclinic sample app shows how to use it.
I certainly understand you're wanting to leverage your expertise in Struts but you might want to take a look at the Spring web tier just for some informative fun.
If you're interested, one of the lead developers of Spring posted a brief comparison of the 2 on the developer email list that covers Webwork also. It also has a 2 sentence explanation to show how you can use Spring from Struts or Webwork.
Let me know if you want it and I will post it here.
Can you tell me any more about the Spring book ?
[ January 16, 2004: Message edited by: Ken Krebs ]
 
Rick Hightower
Author
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't tell you more about the Spring book... yet.
Please post the link.
 
Ken Krebs
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what Juergen Hoeller (one of the lead developers of Spring) said about Spring vs. Struts vs. WebWork:
>From a recent TSS posting of mine:

<quote>
First of all, note a very basic issue: In contrast to Struts or WebWork, Spring is an application framework for all layers, offering a bean configuration foundation, a JDBC abstraction framework, abstract transaction support, etc. It is a very non-intrusive effort: Your application classes do not need to depend on any Spring classes if not necessary, and you can reuse every part on its own if you like to. From its very design, the framework encourages clean separation of tiers, most importantly web tier and business logic: e.g. the validation stuff does not depend on web controllers. Major goals are reusability and testability: Unnecessary container or framework dependencies make this very hard.
Spring's web framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, locale resolution, and view resolution. The default handler is a very simple Controller interface, just offering a "ModelAndView handleRequest(request,response)" method. This can already be used for application controllers, but you will prefer the included implementation hierarchy, consisting of AbstractController, AbstractCommandController, MultiActionController, SimpleFormController, AbstractWizardFormController. Application controllers will typically be subclasses of those. Note that you can choose an appropriate base class: If you don't have a form, you don't need a FormController. This is a major difference to Struts.
You can take any object as command or form object: There's no need to implement an interface or derive from a base class. Spring's data binding is highly flexible, e.g. it treats type mismatches as validation errors that can be evaluated by the application, not as system errors. So you don't need to duplicate your business objects' properties as Strings in your form objects, just to be able to handle invalid submissions, or convert the Strings properly. Instead, it's often preferable to bind directly to your business objects. This is another major difference to Struts which is built around required base classes like Action and ActionForm.
Compared to WebWork: Spring supports the notion of a Controller, an optional command or form object, and a model (normally including the command or form object) that gets passed to the view. Instead, a single WebWork Action object has all those roles. In Spring, command and form objects can be either existing business objects or specialized UI ones. But WebWork requires you do duplicate your business objects' properties in the Action object in any case, mixing validation right into it, and using the same multi-role object for evaluation and form population in the view. For my taste, these are too many roles in one object.
Regarding views: Spring's view resolution is extremely flexible. A controller implementation can even write a view directly to the response, returning null as ModelAndView. Normally, a ModelAndView instance consists of a view name and a model Map, containing bean names and corresponding objects (like a command or form, reference data, etc). View name resolution is highly configurable, either via bean names, via a properties file, or via your own ViewResolver implementation. The abstract model Map allows for complete abstraction of the view technology, without any hassle: be it JSP, Velocity, or anything else - workarounds like a VelocityServlet are unnecessary! The model Map simply gets transformed into an appropriate format, be it JSP request attributes or a Velocity template model.
Finally, if you don't want Spring's web MVC, you can combine Struts or WebWork with the rest of Spring - leveraging all the data access and middle tier stuff that Spring offers. Simply start up a Spring root application context via its ContextLoaderListener, and access it via the ServletContext attribute (or Spring's respective helper method) from within a Struts or WebWork action. All the registered beans including all of Spring's services are still at your fingertips, even without Spring's web MVC.
</quote>

If just focussing on the web support, some of Spring's advantages are:

- clear separation of roles: controller vs validator vs command object vs form object vs model object, DispatcherServlet vs handler mapping vs view resolver, etc;

- powerful and straightforward configuration of both framework and application classes as JavaBeans, including easy in-between referencing via an application context, e.g. from web controllers to business objects and validators;

- adaptability, non-intrusiveness: use whatever Controller subclass you need (plain, command, form, wizard, multi action, or a custom one) for a given scenario instead of deriving from Action/ActionForm for everything;

- customizable binding and validation: type mismatches as application-level validation errors that keep the offending value, localized date and number binding, etc instead of String-only form objects with manual parsing and conversion to business objects;

- reusable business code, no need for duplication: you can use existing business objects as command or form objects instead of mirroring them in special ActionForm subclasses;

- customizable handler mapping, customizable view resolution: flexible model transfer via name/value Map, handler mapping and view resolution strategies from simple to sophisticated instead of one single way;

- customizable locale and theme resolution, support for JSPs with and without Spring tag library, support for JSTL, support for Velocity without the need for extra bridges, etc.

Of course, I haven't even mentioned all the middle tier stuff that we offer (in contrast to both Struts and WebWork), most of it very useful even in typical web applications... :-)
 
Rick Hightower
Author
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of all of the above....


You can take any object as command or form object: There's no need to implement an interface or derive from a base class. Spring's data binding is highly flexible, e.g. it treats type mismatches as validation errors that can be evaluated by the application, not as system errors. So you don't need to duplicate your business objects' properties as Strings in your form objects, just to be able to handle invalid submissions, or convert the Strings properly. Instead, it's often preferable to bind directly to your business objects. This is another major difference to Struts which is built around required base classes like Action and ActionForm.


Sounds the most intriguing....
I like the ideas behind Spring and I plan on using it in my next project.
reply
    Bookmark Topic Watch Topic
  • New Topic