tiles-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anyz <anyz...@gmail.com>
Subject Re: Resource import on individual pages
Date Mon, 14 Dec 2009 08:28:47 GMT
Here is how i'm trying to do it for java imports:
tiles definitions are:
  <definition name=".baseLayout" template="/WEB-INF/tiles/baseLayout.jsp">
      <put-attribute name="pageName"  value="baseLayout"/>
      <put-attribute name="title"  value="Template"/>
 <!-- more goes here -->
  </definition>
  <definition name=".login" extends=".baseLayout">
      <put-attribute name="pageName"  value="login"/>
      <put-attribute name="title"  value="Login"/>
      <put-attribute name="body"
value="/WEB-INF/jsp/publicpages/login.jsp"/>
  </definition>


baeLayout.jsp:

<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/WEB-INF/jsp/common/javaimport.jsp" %>
<html>
 <head>
    </head>
    <body>
   <table width="75%" align="center" cellpadding="3" cellspacing="0"
border="0" class="mainOuterTable">
          <tr>
            <td>
              <tiles:insertAttribute name="header" />
            </td>
          </tr>
          <tr>
            <td>
     <table cellpadding="3" cellspacing="0" border="0" width="100%"
class="tableBorderMain">
      <tr>
       <td>
                <br/><br/>
                   <tiles:insertAttribute name="body" />
                  </td>
                </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td>
            <tiles:insertAttribute name="footer" />
          </td>
        </tr>
      </table>
  </body>
</html>

login.jsp:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

      <form >
User:<input type='text' name='username'/>
Password:<input type='password' name='password'/>
<input name="submit" type="submit" value="Login"/>
       </form>

javaimports.jsp

<c:choose>
 <c:when test = "${pageName=='login'}">
  <%@ page import="java.util.*" %>
 </c:when>
</c:choose>


Although all tag libraries are included in baseLayout.jsp but in login.jsp i
have to redeclare these like <%@ taglib prefix="c" uri="
http://java.sun.com/jsp/jstl/core" %>. SHouldn't login.jsp take it from
baseLayout.jsp?






On Sat, Dec 12, 2009 at 4:49 PM, Antonio Petrelli <
antonio.petrelli@gmail.com> wrote:

> 2009/12/11 anyz <anyz111@gmail.com>:
>  > I have a base tile definition and various tiles extend it. The static
> > resource like css, js are imported throuhg <link> and <Script> tags
in
> base
> > tile. Similalry various java files are imported though import directive
> in
> > base tile jsp page. However each child type has its own js, css and java
> > import file. How can i import resources for individual pages instead of
> > putting everything in base tile. Also html <body> and <head> tags are
> > present only in base tile so is it good practice to import resource in
> child
> > tiles even then.
>
> As Brian anticipated, I have another suggestion :-D
> You can make use of list attributes. I suppose that you have *several*
> js and css files to point to, so in your template page you can do this
> way:
>
> <head>
> <tiles:importAttribute name="javascripts" />
> <c:forEach var="jsfile" items="${javascripts}">
> <script type="text/javascript" src="<tiles:getAsString
> value='${jsfile}' />"></script>
> </c:forEach>
> <!-- The same for css -->
> </head>
>
> Your definition becomes:
>
> <definition name="my.definitio" template="/my/template.jsp">
>  <put-list-attribute name="javascripts">
>    <add-attribute value="/js/script1.js" type="string" />
>    <add-attribute value="/js/script2.js" type="string" />
>  </put-list-attribute>
> </definition>
>
> HTH
> Antonio
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message