wood burning stoves*
The moose likes Struts and the fly likes Tiles advice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Tiles advice" Watch "Tiles advice" New topic
Author

Tiles advice

Juhan Voolaid
Ranch Hand

Joined: Nov 18, 2003
Posts: 179
Hi

I am still very new to struts framework, but I already have done some examples and got them working. Because I am still learning, I want to get it done right and one thing that I am not confident about is using tiles. There are several ways in using the tiles, but I want to know what is the best and most general way of using them.

So what I want:
I have a simple page layout and it consists of two things: navigation menu - just links that stays the same and a content area which needs to be updated after every action.
For example it is a simple e-shop web-application on a very early stage. So the navigation has links to: products, serach product and contact and according to content area, it displays: list of products, serach form and contact information.

So how I would do it:
Create a main layout for the page and then for each new content, I extend a main layout and add information about the content area to tiles-defs.xml:


So then create the jsp files to the "/content" directory, where search-form.jsp and contact.jsp are pages with static information and products.jsp would get its data from database for example.

So for displaying products, I make action class and add action mapping to struts-config.xml:


And in web.xml there is nothing new:



So the links in navigation.jsp would be like so:


I don't deal with product searching right now ...


OK, so that would be it. Would that be a reasonable solution?

And here are my doubts:
1. It is very simpel layout, where only content area changes. Do I really have to make a new layout definition to tiles-defs.xml and make global forward to struts-config.xml, when ever there is new action on the web-app or is there some kind of shortcut?

2. To use tiles, all my links on the navigation and perhaps in content area allso have to be processed through struts-config.xml by forwarding it to proper tiles definition. In other words - all the links must be *.do - so I can apply a layout definiton to it?



That is it for now.

[ April 15, 2006: Message edited by: Juhan Voolaid ]
[ April 17, 2006: Message edited by: Juhan Voolaid ]
Juhan Voolaid
Ranch Hand

Joined: Nov 18, 2003
Posts: 179
Up!
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I am not exactly sure what you are asking. Yes, for each page you create a new tile definition entry that specifies what page to use for the content and you create a new action definition. I suspect that there is a way to forward to a tile definition without going through an action, but I have not done it nor had a desire to do it. If you do not need to perform any processing in your action, you can use one of the built in actions.

- Brent
Juhan Voolaid
Ranch Hand

Joined: Nov 18, 2003
Posts: 179
Originally posted by Brent Sterling:
Yes, for each page you create a new tile definition entry that specifies what page to use for the content and you create a new action definition.

If you do not need to perform any processing in your action, you can use one of the built in actions.

- Brent


Thanx for answering, but could you give a small example of that "built in action"?


Another problem is, that my page has option for logging in and I want to use another layout the page user gets logged in. How could I do that?

In my tiles definitions I already have seperate layouts, for example:


The problem is, if I have a link "/products.do", I want that when user is online, the products-online layout is used and if offline, the prodcts-offline layout is used. Could that be done somehow, or I must use different links, to use different actions, like "/products-online.do" and "/products-offline.do", which would not be that cool


Thanx.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I typically do not use the built in actions...mostly because my actions derived from a base action class that handles some common functionality. Here is the list of non-abstract actions that I see with Struts 1.1: SwitchAction, ForwardAction, and IncludeAction.

It seems possible that you could have your actions return different forwards based on the login status. Say "success-online" and "success-offline". Depending on the difference in the user interface, it might be easier to control the layout in your JSP rather than having different tiles definitions for each page.

- Brent
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Tiles advice
 
Similar Threads
Passing information between tiles
tiles definition error, maping .(dot) error
Change color of clicked link - tiles
Tiles with runtime attributes - response already commited
JSF1.1 and shale-tiles-1.0.4 integration problem