You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by maven apache <ap...@gmail.com> on 2011/02/15 14:53:19 UTC

how to add the js refer in the page which extends the template

Hi:

I have a template,and one of my page(home.jsp) extend this template,this is
the definition file:

<tiles-definitions>

    <definition name="/commonPage" template="/jsp/common/template.jsp">

        <put-attribute name="header" value="/jsp/common/defaultHeader.jsp" />
        <put-attribute name="menu" value="/jsp/common/defaultMenu.jsp" />
        <put-attribute name="footer" value="/jsp/common/defaultFooter.jsp" />

    </definition>


    <definition name="/home" extends="/commonPage">
        <put-attribute name="body" value="/jsp/home_body.jsp" />
    </definition>

    <definition name="/user" extends="/commonPage">
        <put-attribute name="body" value="/jsp/user_body.jsp" />
    </definition>

</tiles-definitions>

home.jsp:

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<tiles:insertDefinition name="/home" />



And now I need some javascripts in the home.jsp,however I do not know where
to add it.

I can add it in the home_body.jsp,but I prefer to add it in a external
file,so where to define it?

I mean where to write this  <script ... src=xx.js /> ?

Thanks.

Re: how to add the js refer in the page which extends the template

Posted by Chris Pratt <th...@gmail.com>.
If you search the list archives, I know I put some examples up here before.
  (*Chris*)

On Tue, Feb 15, 2011 at 6:46 AM, Antonio Petrelli <
antonio.petrelli@gmail.com> wrote:

> 2011/2/15 maven apache <ap...@gmail.com>:
> > 2011/2/15 Antonio Petrelli <an...@gmail.com>
> >
> >> 2011/2/15 maven apache <ap...@gmail.com>:
> >> > And now I need some javascripts in the home.jsp,however I do not know
> >> where
> >> > to add it.
> >> >
> >> > I can add it in the home_body.jsp,but I prefer to add it in a external
> >> > file,so where to define it?
> >> >
> >> > I mean where to write this  <script ... src=xx.js /> ?
> >>
> >> This is the way I prefer, however I think there is plenty of similar,
> >> or better, solutions.
> >> First of all, identify the outer template, the one containing the
> >> <HEAD> elements.
> >> In this template, import a list attribute and iterate over it to
> >> create all script elements:
> >>
> >> <tiles:importAttribute name="scriptList" />
> >> <c:forEach values="${scriptList}" var="script">
> >> <script src="${script}" ...></script>
> >> </c:forEach>
> >>
> >> In all your definitions (or on all base definitions you have) put
> >> these attributes:
> >>
> >> <definition name="...." template="_thetemplateabove_">
> >> <put-list-attribute name="scriptList">
> >> <add-attribute value="/scripts/xx.js">
> >> ...
> >> </put-list-attribute>
> >> </definition>
> >>
> >> Do you like it?
> >>
> >>
> > Thanks for your reply.
> >
> > In fact,I am not exactly sure I know how to do.
> >
> > Can you give me a live example according my example?
>
> No live examples, sorry. This is the doc about list attributes:
> http://tiles.apache.org/framework/tutorial/advanced/list-attributes.html
>
> Antonio
>

Re: how to add the js refer in the page which extends the template

Posted by Antonio Petrelli <an...@gmail.com>.
2011/2/15 maven apache <ap...@gmail.com>:
> 2011/2/15 Antonio Petrelli <an...@gmail.com>
>
>> 2011/2/15 maven apache <ap...@gmail.com>:
>> > And now I need some javascripts in the home.jsp,however I do not know
>> where
>> > to add it.
>> >
>> > I can add it in the home_body.jsp,but I prefer to add it in a external
>> > file,so where to define it?
>> >
>> > I mean where to write this  <script ... src=xx.js /> ?
>>
>> This is the way I prefer, however I think there is plenty of similar,
>> or better, solutions.
>> First of all, identify the outer template, the one containing the
>> <HEAD> elements.
>> In this template, import a list attribute and iterate over it to
>> create all script elements:
>>
>> <tiles:importAttribute name="scriptList" />
>> <c:forEach values="${scriptList}" var="script">
>> <script src="${script}" ...></script>
>> </c:forEach>
>>
>> In all your definitions (or on all base definitions you have) put
>> these attributes:
>>
>> <definition name="...." template="_thetemplateabove_">
>> <put-list-attribute name="scriptList">
>> <add-attribute value="/scripts/xx.js">
>> ...
>> </put-list-attribute>
>> </definition>
>>
>> Do you like it?
>>
>>
> Thanks for your reply.
>
> In fact,I am not exactly sure I know how to do.
>
> Can you give me a live example according my example?

No live examples, sorry. This is the doc about list attributes:
http://tiles.apache.org/framework/tutorial/advanced/list-attributes.html

Antonio

Re: how to add the js refer in the page which extends the template

Posted by maven apache <ap...@gmail.com>.
2011/2/15 Antonio Petrelli <an...@gmail.com>

> 2011/2/15 maven apache <ap...@gmail.com>:
> > And now I need some javascripts in the home.jsp,however I do not know
> where
> > to add it.
> >
> > I can add it in the home_body.jsp,but I prefer to add it in a external
> > file,so where to define it?
> >
> > I mean where to write this  <script ... src=xx.js /> ?
>
> This is the way I prefer, however I think there is plenty of similar,
> or better, solutions.
> First of all, identify the outer template, the one containing the
> <HEAD> elements.
> In this template, import a list attribute and iterate over it to
> create all script elements:
>
> <tiles:importAttribute name="scriptList" />
> <c:forEach values="${scriptList}" var="script">
> <script src="${script}" ...></script>
> </c:forEach>
>
> In all your definitions (or on all base definitions you have) put
> these attributes:
>
> <definition name="...." template="_thetemplateabove_">
> <put-list-attribute name="scriptList">
> <add-attribute value="/scripts/xx.js">
> ...
> </put-list-attribute>
> </definition>
>
> Do you like it?
>
>
Thanks for your reply.

In fact,I am not exactly sure I know how to do.

Can you give me a live example according my example?


>  Antonio
>

Re: how to add the js refer in the page which extends the template

Posted by Antonio Petrelli <an...@gmail.com>.
2011/2/15 maven apache <ap...@gmail.com>:
> And now I need some javascripts in the home.jsp,however I do not know where
> to add it.
>
> I can add it in the home_body.jsp,but I prefer to add it in a external
> file,so where to define it?
>
> I mean where to write this  <script ... src=xx.js /> ?

This is the way I prefer, however I think there is plenty of similar,
or better, solutions.
First of all, identify the outer template, the one containing the
<HEAD> elements.
In this template, import a list attribute and iterate over it to
create all script elements:

<tiles:importAttribute name="scriptList" />
<c:forEach values="${scriptList}" var="script">
<script src="${script}" ...></script>
</c:forEach>

In all your definitions (or on all base definitions you have) put
these attributes:

<definition name="...." template="_thetemplateabove_">
<put-list-attribute name="scriptList">
<add-attribute value="/scripts/xx.js">
...
</put-list-attribute>
</definition>

Do you like it?

Antonio