You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Cedric Dumoulin <ce...@apache.org> on 2003/03/04 18:34:38 UTC
Re: Tiles problems (Building complex pages)
Hi,
It looks like your unlucky using Tiles ;-).
Fabio Mancinelli wrote:
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>
>Hi all,
>
>Sorry for this lengthy mail but I am getting crazy!
>I am working with Struts and Tiles and I am developing a small site to
>test (and stress this technology)
>
>I reused some layouts taken from the tiles documentation. The standard
>page layout with the classical header, body, footer attributes and, in
>particular I took the vboxLayout:
>
><%
> Iterator i = list.iterator();
> while(i.hasNext()) {
> String name = (String)i.next();
>%>
> <tiles:insert name="<%= name %>" flush="true"/>
><%
> }
>%>
>
>What I want is a page with the standard layout whose body is a vboxLayout
>with some tiles.
>
>To do this I have to write the following files:
>main.jsp
>
If you use the tiles-config.xml, you can replace this page by a Struts
action forwarding to a definition.
>mainBody.jsp
>
As it use the vboxLayout.jsp, you can alsoreplace this page by a
definition
>t1.jsp
>t2.jsp
>
These are your bodies, you need them ;-)
>
>Where main is a page which uses the standard layout, mainBody is a simple
>.jsp with only a
>
><tiles:insert page="vboxLayout.jsp">
><tiles:putList name="list">
><tiles:add value="t1.jsp"/>
><tiles:add value="t2.jsp"/>
>...
>t1, t2 are .jsp tiles.
>
>Now my questions are:
>
>1) The mainBody contains a list of tiles some of which might be text-only.
>I would like to do something like this:
><tiles:insert page="vboxLayout.jsp">
><tiles:putList name="list">
><tiles:add value="t1.jsp"/>
><tiles:add type="string">This is an embedded text only tile</tiles:add>
>...
>In this way I would get rid of all the .jsp which contains only text/html
>and are peculiar to a single page. But this doesn't work.
>
This is useful only if the body contains small text, and preferably
without tags.
Specifying type="String" should work.
>
>2) Another problem is when a tile, let's say t1.jsp, needs some attributes
>to be passed in order to be instantiated. Let's suppose that the tile t1
>needs a title. How do I pass that attribute in the previous example?
>
You can define another definition declaring your attributes. Then, you
specify the definition instead of the jsp url:
<definition name="t1" page="/t1.jsp" >
<put name="title" value="Yupi"/>
<definition/>
<definition name="body" page="/layouts/vboxLayout.jsp" >
<putList name="list" >
<add value="t1"/>
<add value="/t1.jsp"/>
</putList>
<definition/>
>
><tiles:insert page="vboxLayout.jsp">
><tiles:putList name="list">
><tiles:add value="t1.jsp">
> <tiles:put name="title" value="Yupi"/>
></tiles:add>
><tiles:add value="t2.jsp"/>
>...
>Doesn't work.
>
>I tried to write a local definition before actually inserting the tile:
>
><tiles:definition id="instantiatedT1" page="t1.jsp">
><tiles:put name="title" value="Yupi"/>
></tiled:definition>
>
This define a definition defined in a jsp scope.
>
><tiles:insert page="vboxLayout.jsp">
><tiles:putList name="list">
><tiles:add value="instantiatedT1"/>
>
You need to do somethink like:
<tiles:add beanName="instantiatedT1"/>
But I am not sure that the vboxLayout support a definition bean as list
element. Definitions are more useful when defined in the tiles factory
from a tiles-config.xml file.
><tiles:add value="t2.jsp"/>
>...
>But this doesn't work too. I tried also to specify different scopes for
>the definition (even the application one!) and different types for the
><tiles:add> tag (namely type="definition" and also
>beanName="instantiatedT1").
>The only way I've found to make this work is to put the definition inside
>the tiles-config.xml, but this would be equivalent in having a separate t1.jsp
>with no parameters.
>
>I suppose the problem is in the vboxLayout but I cannot figure out how to
>write a layout which supports what I said in 1).
>The problem in 2) still has no solution (to me).
>
I suggest that you use the tiles-config.xml file. It will help reduce
the number of pages. I also suggest to have one jsp per tiles, and to
not write big pieces of body inside a <put> tag.
Also, don't forget that you can write your own layout doing the exact
behavior that you are looking for.
Cedric
>
>A presto,
>Fabio
>
>- --
>- -----------------------------------------------------------------------------
> Fabio Mancinelli, PhD student EMail : mancinel@di.univaq.it
> Dipartimento di Informatica WWW : http://www.di.univaq.it/~mancinel
> Universita' dell'Aquila
>- -----------------------------------------------------------------------------
>
>
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.0.6 (GNU/Linux)
>Comment: Made with pgp4pine 1.75-6
>
>iD8DBQE+ZKrs6dsQbk2R3cMRArgjAKCcW4oqazE/lbRwXBnOEA7odtvTyACgzw9p
>oSPR57Gl6YLcMAA6B08KZbo=
>=BmVa
>-----END PGP SIGNATURE-----
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Tiles problems (Building complex pages)
Posted by Cedric Dumoulin <ce...@apache.org>.
Fabio Mancinelli wrote:
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>On Tue, 4 Mar 2003, Cedric Dumoulin wrote:
>
>
>
>> Hi,
>>
>> It looks like your unlucky using Tiles ;-).
>>
>>
>>
>Thank you for your answers. I admit that some of my questions were a bit
>brain-damaged :) Anyway passing a definition to the vboxLayout via the
><add beanName="..."/> doesn't work because all the passed attributes are
>inserted in the vboxLayout by using a <insert name="..."/>
>
>I made it work by modifying the vboxLayout in this way:
>
>...
><%
> Iterator i = list.iterator();
> while(i.hasMoreElement()) {
> String name = (String)i.next();
>%>
><logic:present name="<%= name %>">
><%--A bean is present with the attribute name so it should be a definition--%
><tiles:insert beanName="<%= name %>"/>
></logic:present>
><logic:notPresent name="<%= name %>">
><%--Standard tiles insertion-->
><tiles:insert name="<%= name %>"/>
></logic:notPresent>
><%
> }
>%>
>
>So, when I insert that tile I alway use
><add name="..."/> regardless if I am passing a definition (local or
>tile-config defined) or a path to another tile.This is necessary, I
>think, because <add beanName> doesn't work at all. Do you think this is a
>reasonable solution?
>
I think this is a good solution.
Cedric
>
>However this solution fails for adding normal strings, but I agree with
>you (Cedric) that you should not compose body tiles with a list of small
>strings packed in a vboxLayout! :) So the lack of support for normal
>strings isn't really an issue!
>
>A presto,
>Fabio
>
>- --
>- -----------------------------------------------------------------------------
> Fabio Mancinelli, PhD student EMail : mancinel@di.univaq.it
> Dipartimento di Informatica WWW : http://www.di.univaq.it/~mancinel
> Universita' dell'Aquila
>- -----------------------------------------------------------------------------
>
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.0.6 (GNU/Linux)
>Comment: Made with pgp4pine 1.75-6
>
>iD8DBQE+ZRG96dsQbk2R3cMRAhwpAKDE6JedQaXKz6I4sg4SjMVovJ2OOgCfb1HE
>URKleHqTlaYkxtJS5p7izZg=
>=PdU8
>-----END PGP SIGNATURE-----
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Tiles problems (Building complex pages)
Posted by Fabio Mancinelli <ma...@di.univaq.it>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Tue, 4 Mar 2003, Cedric Dumoulin wrote:
>
> Hi,
>
> It looks like your unlucky using Tiles ;-).
>
Thank you for your answers. I admit that some of my questions were a bit
brain-damaged :) Anyway passing a definition to the vboxLayout via the
<add beanName="..."/> doesn't work because all the passed attributes are
inserted in the vboxLayout by using a <insert name="..."/>
I made it work by modifying the vboxLayout in this way:
...
<%
Iterator i = list.iterator();
while(i.hasMoreElement()) {
String name = (String)i.next();
%>
<logic:present name="<%= name %>">
<%--A bean is present with the attribute name so it should be a definition--%
<tiles:insert beanName="<%= name %>"/>
</logic:present>
<logic:notPresent name="<%= name %>">
<%--Standard tiles insertion-->
<tiles:insert name="<%= name %>"/>
</logic:notPresent>
<%
}
%>
So, when I insert that tile I alway use
<add name="..."/> regardless if I am passing a definition (local or
tile-config defined) or a path to another tile.This is necessary, I
think, because <add beanName> doesn't work at all. Do you think this is a
reasonable solution?
However this solution fails for adding normal strings, but I agree with
you (Cedric) that you should not compose body tiles with a list of small
strings packed in a vboxLayout! :) So the lack of support for normal
strings isn't really an issue!
A presto,
Fabio
- --
- -----------------------------------------------------------------------------
Fabio Mancinelli, PhD student EMail : mancinel@di.univaq.it
Dipartimento di Informatica WWW : http://www.di.univaq.it/~mancinel
Universita' dell'Aquila
- -----------------------------------------------------------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Made with pgp4pine 1.75-6
iD8DBQE+ZRG96dsQbk2R3cMRAhwpAKDE6JedQaXKz6I4sg4SjMVovJ2OOgCfb1HE
URKleHqTlaYkxtJS5p7izZg=
=PdU8
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org