Click Framework And Jsp: Notes

ClickFrameworkAndJsp

===========
Rendered page example:
http://www.avoka.com/click-examples/jsp/customer-table.htm
Source:
http://www.avoka.com/click-examples/source-viewer.htm?filename=/jsp/customer-table.htm

customer-table.jsp (src code) ==============>when accessing from browser: it should be accessed AS

customer-table.htm—this auto mapped to

customer-table.jsp-map to

CustomerTable.java

(if accessing it as .jsp, page is not rendered correctly)

This will first invoke customer-table.jsp,

-then invoke CustomerTable.java

-then invoke border-template.jsp as indicated in getTemplate method in above .java

– then render customer-table.htm (mapped to .jsp) via ${forward} in border-template.jsp when rendering border-template.jsp

(template is also a .jsp file.

…………….

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

<style type=”text/css”>
th { color: white; }
</style>

<p>
Example JSP customers table.
</p>

<table style=”border: 1px solid black;” cellpadding=”6″ cellspacing=”0″>
<tr valign=”baseline” bgcolor=”404060″>
<th align=”center”> ID </th>
<th align=”left”> Name </th>
<th align=”left”> Email </th>
<th align=”center”> Age </th>
<th align=”left”> Category </th>
<th align=”center”> Portfolio </th>
<th align=”right”> Date Joined </th>
<th align=”center”> Active </th>
</tr>

<c:forEach var=”customer” items=”${customers}” varStatus=”lineInfo”>

<c:choose>
<c:when test=”${lineInfo.count % 2 == 0}”> <tr bgcolor=”#f7f7e7″> </c:when>
<c:otherwise> <tr bgcolor=”white”> </c:otherwise>
</c:choose>

<td align=”center”> ${customer.id} </td>
<td align=”left”> ${customer.name} </td>
<td align=”left”> <a href=”${customer.email}”>${customer.email}</a> </td>
<td align=”center”> ${customer.age} </td>
<td align=”left”> ${customer.investments} </td>
<td align=”right”> <fmt:formatNumber value=”${customer.holdings}” type=”currency”/></td>
<td align=”right”> <fmt:formatDate value=”${customer.dateJoined}” pattern=”dd MMM yyyy”/> </td>

<td align=”center”>
<c:choose>
<c:when test=”${customer.active}”> <input type=”checkbox” checked=”checked”/> </c:when>
<c:otherwise> <input type=”checkbox”/> </c:otherwise>
</c:choose>
</td>

</tr>

</c:forEach>

</table>

<p>&nbsp;</p>

The <tt>CustomerTable</tt> page is automatically mapped to the request:

<pre class=”codeConfig”>
GET customer-table.htm </pre>

When pages are configured to use automapping the <tt>ClickServlet</tt>
will automatically associated the file path <tt>customer-table.jsp</tt>
with the page class <tt>CustomerTable</tt>.

===========
http://www.avoka.com/click-examples/source-viewer.htm?filename=WEB-INF/classes/org/apache/click/examples/page/jsp/CustomerTable.java

package org.apache.click.examples.page.jsp;

import java.util.List;

import org.apache.click.examples.page.BorderPage;

/**
* Provides JSP Page example where a JSP page and JSP border template is used to
* render a table.
*
* @author Malcolm Edgar
*/
public class CustomerTable extends BorderPage {

public List customers = null;

/**
* @see org.apache.click.Page#onRender()
*/
public void onRender() {
customers = getCustomerService().getCustomersSortedByName(10);
}

/**
* Returns the name of the border template: &nbsp; <tt>”/border-template.jsp”</tt>
*
* @see org.apache.click.Page#getTemplate()
*/
public String getTemplate() {
return “/border-template.jsp”;
}

}

======================
This is the template file:

http://fisheye6.atlassian.com/browse/click/trunk/click/examples/webapp/border-template.jsp?r=787399

<!doctype html>
2
sabob 724639 3 <!–
4 Licensed to the Apache Software Foundation (ASF) under one
5 or more contributor license agreements.  See the NOTICE file
6 distributed with this work for additional information
7 regarding copyright ownership.  The ASF licenses this file
8 to you under the Apache License, Version 2.0 (the
9 “License”); you may not use this file except in compliance
10 with the License.  You may obtain a copy of the License at
11
12 http://www.apache.org/licenses/LICENSE-2.0
13
14 Unless required by applicable law or agreed to in writing,
15 software distributed under the License is distributed on an
16 “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 KIND, either express or implied.  See the License for the
18 specific language governing permissions and limitations
19 under the License.
20 –>
malcolm_edgar 715468 21
22
sabob 787399 23 <%– Menu –%>
24 <table id=“menuTable” border=“0” width=“100%” cellspacing=“0” cellpadding=“0” style=“margin-top: 2px;”>
25 <tr>
26 <td>
27 <div class=“menustyle” id=“menu”>
28 <ul class=“menubar” id=“dmenu”>
29 <c:forEach items=“${rootMenu.children}” var=“topMenu”>
30 <li class=“topitem”>${topMenu}
31 <ul class=“submenu”
32 <c:forEach items=“${topMenu.children}” var=“subMenu”>
33 ><li>${subMenu}</li
34 </c:forEach>
35 ></ul>
36 </li>
37 </c:forEach>
38 <li class=“topitem”><a target=“_blank” href=“${context}/source-viewer.htm?filename=WEB-INF/classes/${srcPath}” title=“Page Java source”><img border=“0” class=“link” alt=“” src=“${context}/assets/images/lightbulb1.png”/> Page Java</a>
39 </li>
40 <li class=“topitem”><a target=“_blank” href=“${context}/source-viewer.htm?filename=${path}” title=“Page Content source”><img border=“0” class=“link” alt=“” src=“${context}/assets/images/lightbulb2.png”/> Page HTML</a>
41 </li>
42 </ul>
43 </div>
44 </td>
45 </tr>
46 </table>
47 </div>
malcolm_edgar 715468 48
sabob 787399 49 <%– Page Content –%>
50 <div class=“content”>
51 <h2>${title}</h2>  <============ from BorderPage.java
52 <p/>
sabob 782056 53 <jsp:include page=${forward} flush=“true”/>  <============= htm equivalent of path; the .htm page requested, in this case it renders requesing .htm page: customer-table.htm
sabob 787399 54 </div>
55
56 </div>
malcolm_edgar 715468 57
sabob 757699 58 ${jsElements}
59
malcolm_edgar 715468 60 </body>
malcolm_edgar 716421 61 </html>

=========imports for jsp==========
http://incubator.apache.org/click/docs/click-api/org/apache/click/util/PageImports.html

public class PageImportsextends Object

Provides a utility object for rendering a Page’s HTML header imports and its control HTML header imports.

A PageImports instance is automatically added to the Velocity Context for Velocity templates, or as a request attribute for JSP pages using the key name “imports“.

PageImports Examples

To use the PageImports object simply reference it your page header section. For example: <html>
<head>
$imports
</head>
<body>
$form
<body>
</html>
imports” include all javascript and stylesheet imports.
PageImports also provides a way of including the javascript and stylesheet separately using the key names “cssImports” and “jsImports“.

You should follow the performance best practice by importing CSS includes in the head section, then include the JS imports after the html body. For example:

<html>
<head>
$cssImports
</head>
<body>
$form
<br/>
$table
<body>
</html>
$jsImports
Please also see Page.getHtmlImports() and Control.getHtmlImports().