I have created a working webapp that combines Shale 1.1.0 snapshot
20070409 and the tiles jar that came with this
snapshot---tiles-core-2.0-r468346-SNAPSHOT.jar along with the supplied
MyFaces 1.1.4 jars deployed on either Tomcat 5.5.17 or 6.0.10. The
webapp is setup as follows (starting from the webapp root):

/index.jsp:

<jsp:forward page="/tiles/layouts/loadLayout.faces"/>

/tiles/layouts/loadLayout.jsp:

<%@ taglib uri="http://java.sun.com/jsf/core"; prefix="f" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles"; prefix="tiles" %>

<tiles:insertDefinition name="/contentPage" flush="false"/>

/WEB-INF/tiles-defs.xml:

<?xml version="1.0" encoding="ISO-8859-1" ?>

 <!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
       "http://struts.apache.org/dtds/tiles-config_2_0.dtd";>

<tiles-definitions>  
    <definition name="/mainLayout" template="/tiles/layouts/siteLayout.jsp">
        <put name="htmlHeader" type="template"
value="/tiles/htmlHeaderTile.jsp"/>
        <put name="header" type="template" value="/tiles/headerTile.jsp"/>
        <put name="rightSideBar" type="template"
value="/tiles/rightSideBarTile.jsp"/>
        <put name="footer" type="template" value="/tiles/footerTile.jsp"/>
    </definition>

    <definition name="/contentPage" extends="/mainLayout">
        <put name="content" type="template" value="/tiles/homeTile.jsp"/>
    </definition>
</tiles-definitions>

/tiles/homeTile.jsp:

<%@ taglib uri="http://java.sun.com/jsf/core"; prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html"; prefix="h" %>
<%@ taglib uri="http://myfaces.apache.org/tomahawk"; prefix="t" %>

<h:outputText value=
"<h1 align='center'>An OutputText Method to do a Content Tile!</h1>
    <div>
        <p>
            A paragraph of content.
        <p>
            A second paragraph of content.
        <p>
            A third paragraph of content.
    </div><br>
" escape="false"/>

<h:outputText value="Some JSF output text."/>

<f:verbatim>
    <h1 align='center'>A Verbatim Method to do The Same Content Tile!</h1>
    <div>
        <p>
            Another paragraph of content.       
        <p>
            Another second paragraph of content.
        <p>
            Another third paragraph of content.
    </div><br>
</f:verbatim>
<h:outputText value="Some more JSF output text."/>

/tiles/layouts/siteLayout.jsp

<%@ taglib uri="http://java.sun.com/jsf/core"; prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html"; prefix="h" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles"; prefix="tiles" %>

<html lang="en">
    <f:view>
        <head>
            <tiles:attribute name="htmlHeader" flush="false"/>
        </head>
        <body leftmargin="0" topmargin="0" marginwidth="0"
marginheight="0" style="margin:0;padding:0">
            <h:panelGrid columns="1" border="3">
                <h:panelGroup>
                    <tiles:attribute name="header" flush="false"/>
                </h:panelGroup>
                <h:panelGroup>
                    <h:panelGrid columns="2" border="1">
                        <h:panelGroup>
                            <tiles:attribute name="content" flush="false"/>
                        </h:panelGroup>
                        <h:panelGroup>
                            <tiles:attribute name="rightSideBar"
flush="false"/>
                        </h:panelGroup>
                    </h:panelGrid>
                </h:panelGroup>
                <h:panelGroup>
                    <h:outputText value="Directly from sitelayout page: "/>
                    <h:inputText/>
                </h:panelGroup>
                <h:panelGroup>
                    <tiles:attribute name="footer" flush="false"/>
                </h:panelGroup>
            </h:panelGrid>
        </body>
    </f:view>
</html>

I am also using the tiles listener from web.xml as follows:

  <listener>
    <listener-class>
      org.apache.tiles.listener.TilesListener
    </listener-class>
  </listener>

instead of the Shale tiles view handler (if this makes a difference) in
faces-config.xml:

  <!-- application>   
    <view-handler>
      org.apache.shale.tiles.TilesViewHandler
    </view-handler>
  </application -->

which I could not get to work.

I have omitted the other tiles, but they just have some simple text or
JSF tags in them as dummy filler.

This works as I expect it to with everything displayed in proper order, etc.

However, this scheme forces me to create two pages for every unique
content page I wish to display. For instance, if I want to display a
different content page instead of the home tile, I might add a
definition in tiles-defs.xml as follows:

    <definition name="/contactUsPage" extends="/mainLayout">
        <put name="content" type="template"
value="/tiles/contactUsTile.jsp"/>
    </definition>

if I wanted to create new content containing contact information on a
contact us page. But with the scheme that I have described above, in
order to reference this new definition, I also have to create a new
loadContactLayout.jsp page with a definition as follows:

<%@ taglib uri="http://java.sun.com/jsf/core"; prefix="f" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles"; prefix="tiles" %>

<tiles:insertDefinition name="/contactUsPage" flush="false"/>

Now for the Struts/Tiles portion:

In Struts/Tiles I was able to simply declare a global forward and an
action as follows:
       <forward
            name="Welcome"
            path="/Welcome.do"/>

       <action
            path="/Welcome"
            forward=".welcomePage"/>

The action's forward leads to a similar pair of tiles definitions in a
tiles-def.xml file as follows:

    <definition name=".mainLayout" path="/tiles/layouts/siteLayout.jsp">
        <put name="htmlHeader" value="../htmlHeaderTile.jsp"/>
        <put name="header" value="../headerTile.jsp"/>
        <put name="rightSideBar" value="../rightSideBarTile.jsp"/>
        <put name="footer" value="../footerTile.jsp"/>
    </definition>

    <definition name=".welcomePage" extends=".mainLayout">
        <put name="content" value="../homeTile.jsp"/>
    </definition>

with a siteLayout.jsp page:

...snip...
<html:html locale="true">
    <head>
        <tiles:insert attribute="htmlHeader"/>
    </head>
...snip...


I can then simply define a URL as http://.../mywebapp/Welcome.do and
this causes the tiles context to be instantiated and then causes the
appropriate home tile to be rendered on the client. This Struts/Tiles
scheme does not need the loadLayout insertDefinition page.

The Shale/JSF/Tiles scheme that I currently have working seems really
clunky.

Is there some way that I can reduce the two pages down to one page under
Shale/JSF/Tiles?

Also, I would be happy to share this war file or a more elegant one
hopefully, if the group feels that this would be useful for others. I
had to spend significant time to get this working example up and running
and having a working example close to the head of the repository might
be useful to others. Would it be worthwhile posting this or a modified
war on JIRA for example?

                                            -=> Gregg <=-


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to