You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Chris Dailey <mo...@intranet.org> on 2009/06/21 19:17:28 UTC

JSF and Tiles2

Greetings,

I have been coming back to Java after a long hiatus, learning JSF using 
the Core JavaServer Faces 2nd ed by David Geary and Cay Horstmann.  
Chapter 8 is "Subviews and Tiles".  It is all based on the first Tiles, 
and the only tricky part of getting it to work with Tiles2 was getting 
the data from the ViewPreparer that was more easily available in the old 
Controller.

Anyways, for this chapter and most of the others on the net, it 
describes a method of creating re-usable pieces, but they all only 
really show one page using the scenario.  I'm having a hard time seeing 
how it scales to many pages using the same templates.  If I have a 
scenario where I have many pages with just the content area unique to 
each page (but a common header, left nav, and footer), I think the 
process I have to do is:

ONCE:
1. Create a generic template JSP, called /template/standardHeader.jsp.  
It includes place-holders (tiles:insertAttribute tags) for header, 
leftnav, footer, and content.
2. Create a definition called "standardHdr" in tiles-def with 
appropriate put-attribute values for header, leftnav, and footer, as 
well as a default title (but NOT content).
FOR EACH PAGE is:

1. Add another definition "page1definition" (or page2definition, etc.) 
in the tiles-defs.xml that extends standardHdr.  To the definition also 
I add in the title attribute, and for the content attribute I point to a 
page called "/page1content.jsp" (or page2content.jsp, etc.)
2. Create "page1content.jsp" (or page2content.jsp, etc.), which has only 
the content.
3. Create "page1.jsp" (or page2.jsp, etc.)

That looks like a lot of overhead for each page I want to add.  Am I 
doing it wrong?  Is there an easier way?  Maybe something with just a 
single file per new page that says "here's the tiles definition to use" 
and "here's the content I want to use"?

I tried to come up with a solution using "Runtime Composition" as 
described here:
http://tiles.apache.org/framework/tutorial/advanced/runtime.html
But it didn't work.  You can't put JSP/JSF code within a 
<tiles:putAttribute>, nor point to it using a facet, etc.  As far as I 
can tell you HAVE to have a separate file.

I've done a bit of looking through documentation and Googling, but I 
haven't found an example yet.  Any pointers would be appreciated.

Thanks a lot!
Chris

Re: JSF and Tiles2

Posted by Antonio Petrelli <an...@gmail.com>.
2009/6/22 Chris Dailey <mo...@intranet.org>

> I just discovered the page describing Wildcard support, and was wondering
> if it could be applied to this problem.
> http://tiles.apache.org/framework/tutorial/advanced/wildcard.html
>
> I am guessing I would want to:
>
> <definition name="standardHdr.*:--:*"
> template="/template/standardHeader.jsp">
>  <put-attribute name="header" value="/template/header.jsp"/>
>  <put-attribute name="leftnav" value="/template/leftnav.jsp"/>
>  <put-attribute name="footer" value="/template/footer.jsp"/>
>  <put-attribute name="content" value="{1}"/>
>  <put-attribute name="title" value="{2}"/>
> </definition>
>
> page1.jsp:
> <tiles:insertDefinition name="standardHdr./page1content.jsp:--:Page One
> Content"/>
> page1content.jsp:
> (contains whatever the content is)
>
> I don't have to add an extra definition for each page, but there are still
> 2 JSP pages for every page that uses that definition.
>
> Please let me know whether there is a 1-page solution.
>


You can use the ViewHandler that Apache Myfaces provides:
http://myfaces.apache.org/tomahawk/tiles.html

But you have to use this view handler (don't know if it works though):
http://myfaces.apache.org/tomahawk-project/tomahawk12/apidocs/org/apache/myfaces/tomahawk/application/jsp/JspTilesTwoViewHandlerImpl.html

This way you can specify the name of the definition as the view id.

HTH
Antonio

Re: JSF and Tiles2

Posted by Chris Dailey <mo...@intranet.org>.
I just discovered the page describing Wildcard support, and was 
wondering if it could be applied to this problem.
http://tiles.apache.org/framework/tutorial/advanced/wildcard.html

I am guessing I would want to:

<definition name="standardHdr.*:--:*" 
template="/template/standardHeader.jsp">
  <put-attribute name="header" value="/template/header.jsp"/>
  <put-attribute name="leftnav" value="/template/leftnav.jsp"/>
  <put-attribute name="footer" value="/template/footer.jsp"/>
  <put-attribute name="content" value="{1}"/>
  <put-attribute name="title" value="{2}"/>
</definition>

page1.jsp:
<tiles:insertDefinition name="standardHdr./page1content.jsp:--:Page One 
Content"/>
page1content.jsp:
(contains whatever the content is)

I don't have to add an extra definition for each page, but there are 
still 2 JSP pages for every page that uses that definition.

Please let me know whether there is a 1-page solution.

Thanks,
Chris

Chris Dailey wrote:
> Greetings,
>
> I have been coming back to Java after a long hiatus, learning JSF 
> using the Core JavaServer Faces 2nd ed by David Geary and Cay 
> Horstmann.  Chapter 8 is "Subviews and Tiles".  It is all based on the 
> first Tiles, and the only tricky part of getting it to work with 
> Tiles2 was getting the data from the ViewPreparer that was more easily 
> available in the old Controller.
>
> Anyways, for this chapter and most of the others on the net, it 
> describes a method of creating re-usable pieces, but they all only 
> really show one page using the scenario.  I'm having a hard time 
> seeing how it scales to many pages using the same templates.  If I 
> have a scenario where I have many pages with just the content area 
> unique to each page (but a common header, left nav, and footer), I 
> think the process I have to do is:
>
> ONCE:
> 1. Create a generic template JSP, called 
> /template/standardHeader.jsp.  It includes place-holders 
> (tiles:insertAttribute tags) for header, leftnav, footer, and content.
> 2. Create a definition called "standardHdr" in tiles-def with 
> appropriate put-attribute values for header, leftnav, and footer, as 
> well as a default title (but NOT content).
> FOR EACH PAGE is:
>
> 1. Add another definition "page1definition" (or page2definition, etc.) 
> in the tiles-defs.xml that extends standardHdr.  To the definition 
> also I add in the title attribute, and for the content attribute I 
> point to a page called "/page1content.jsp" (or page2content.jsp, etc.)
> 2. Create "page1content.jsp" (or page2content.jsp, etc.), which has 
> only the content.
> 3. Create "page1.jsp" (or page2.jsp, etc.)
>
> That looks like a lot of overhead for each page I want to add.  Am I 
> doing it wrong?  Is there an easier way?  Maybe something with just a 
> single file per new page that says "here's the tiles definition to 
> use" and "here's the content I want to use"?
>
> I tried to come up with a solution using "Runtime Composition" as 
> described here:
> http://tiles.apache.org/framework/tutorial/advanced/runtime.html
> But it didn't work.  You can't put JSP/JSF code within a 
> <tiles:putAttribute>, nor point to it using a facet, etc.  As far as I 
> can tell you HAVE to have a separate file.
>
> I've done a bit of looking through documentation and Googling, but I 
> haven't found an example yet.  Any pointers would be appreciated.
>
> Thanks a lot!
> Chris
>


Re: JSF and Tiles2

Posted by Antonio Petrelli <an...@gmail.com>.
Sorry, I cannot understand your question.
Can you write a graphical scheme to show what you want to achieve?

Antonio

2009/6/21 Chris Dailey <mo...@intranet.org>

> Greetings,
>
> I have been coming back to Java after a long hiatus, learning JSF using the
> Core JavaServer Faces 2nd ed by David Geary and Cay Horstmann.  Chapter 8 is
> "Subviews and Tiles".  It is all based on the first Tiles, and the only
> tricky part of getting it to work with Tiles2 was getting the data from the
> ViewPreparer that was more easily available in the old Controller.
>
> Anyways, for this chapter and most of the others on the net, it describes a
> method of creating re-usable pieces, but they all only really show one page
> using the scenario.  I'm having a hard time seeing how it scales to many
> pages using the same templates.  If I have a scenario where I have many
> pages with just the content area unique to each page (but a common header,
> left nav, and footer), I think the process I have to do is:
>
> ONCE:
> 1. Create a generic template JSP, called /template/standardHeader.jsp.  It
> includes place-holders (tiles:insertAttribute tags) for header, leftnav,
> footer, and content.
> 2. Create a definition called "standardHdr" in tiles-def with appropriate
> put-attribute values for header, leftnav, and footer, as well as a default
> title (but NOT content).
> FOR EACH PAGE is:
>
> 1. Add another definition "page1definition" (or page2definition, etc.) in
> the tiles-defs.xml that extends standardHdr.  To the definition also I add
> in the title attribute, and for the content attribute I point to a page
> called "/page1content.jsp" (or page2content.jsp, etc.)
> 2. Create "page1content.jsp" (or page2content.jsp, etc.), which has only
> the content.
> 3. Create "page1.jsp" (or page2.jsp, etc.)
>
> That looks like a lot of overhead for each page I want to add.  Am I doing
> it wrong?  Is there an easier way?  Maybe something with just a single file
> per new page that says "here's the tiles definition to use" and "here's the
> content I want to use"?
>
> I tried to come up with a solution using "Runtime Composition" as described
> here:
> http://tiles.apache.org/framework/tutorial/advanced/runtime.html
> But it didn't work.  You can't put JSP/JSF code within a
> <tiles:putAttribute>, nor point to it using a facet, etc.  As far as I can
> tell you HAVE to have a separate file.
>
> I've done a bit of looking through documentation and Googling, but I
> haven't found an example yet.  Any pointers would be appreciated.
>
> Thanks a lot!
> Chris
>