Apache Tiles Configuration

Apache Tiles Configuration:

Add jars:
commons-beanutils-1.8.0
commons-digester-1.8.1
commons-logging-1.1.1
log4j-1.2.16
slf4j-api-1.6.1
slf4j-log4j12-1.6.1
tiles-api-2.2.2
tiles-core-2.2.2
tiles-jsp-2.2.2
tiles-servlet-2.2.2
tiles-template-2.2.2

1. Add this to the web.xml

    <context-param>
        <param-name>
            org.apache.tiles.definition.DefinitionsFactory.DEFINITIONS_CONFIG
        </param-name>
        <param-value>
            /WEB-INF/TilesConfig.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>
            org.apache.tiles.web.startup.TilesListener
        </listener-class>
    </listener>

2. Add this to the TilesConfig.xml (same directory path with the web.xml)

<tiles-definitions>
    <definition name=”homePage” template=”/WEB-INF/tilesdesign/template.jsp”>
        <put-attribute name=”header” value=”/WEB-INF/tilesdesign/defaultHeader.jsp” />
        <put-attribute name=”menu” value=”/WEB-INF/tilesdesign/defaultMenu.jsp” />
        <put-attribute name=”body” value=”/WEB-INF/jsp/content/home_body.jsp” />
        <put-attribute name=”footer” value=”/WEB-INF/tilesdesign/defaultFooter.jsp” />
    </definition>
</tiles-definitions>

3. Design and layout different pages (header, menu, body, footer etc..) defined in the TilesConfig.xml

->template.jsp
  should contain the overall design of the site. include here the header, body, menu, footer, etc.
  add the tiles tag-library

e.g.
<%@ taglib uri=”http://tiles.apache.org/tags-tiles” prefix=”tiles” %>

<html>
    <body style=”width:100%;height:100%”>
        <table border=”1” cellspacing=”0” cellpadding=”0” style=”width:100%;height:100%”>
            <tr>
                <td colspan=”2”>
                    <tiles:insertAttribute name=”header” /></td>
            </tr>
            <tr>
                <td>
                    <tiles:insertAttribute name=”menu” /></td>
                <td>
                    <tiles:insertAttribute name=”body” /></td>
            </tr>
            <tr>
                <td colspan=”2”>
                    <tiles:insertAttribute name=”footer” /></td>
            </tr>
        </table>
    </body>
</html>

->defaultHeader.jsp
  <div>this is the default header</div>

->defaultMenu.jsp
  <div>
    <ul>
        <li>Menu item 1</li>
        <li>Menu item 2</li>
        <li>Menu item 3</li>
        <li>Menu item 4</li>
        <li>Menu item 5</li>
        <li>Menu item 6</li>
    </ul>
  </div>

->home_body.jsp
  <div id=”header”>
    <h1>This is the home page’s body</h1>
  </div>

->defaultFooter.jsp
  <div>this is the default footer</div>


4. create containers of the page contents

->home.jsp
This page only tells Tiles which definition to use. Then Tiles can read that definition to
find which template to take, and for each part of the template, what to insert.

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

5. to add another page, the new content of TilesConfig.xml will be

<tiles-definitions>
    <definition name=”homePage” template=”/WEB-INF/tilesdesign/template.jsp”>
        <put-attribute name=”header” value=”/WEB-INF/tilesdesign/defaultHeader.jsp” />
        <put-attribute name=”menu” value=”/WEB-INF/tilesdesign/defaultMenu.jsp” />
        <put-attribute name=”body” value=”/WEB-INF/jsp/content/home_body.jsp” />
        <put-attribute name=”footer” value=”/WEB-INF/tilesdesign/defaultFooter.jsp” />
    </definition>
   
    <definition name=”aboutPage” template=”/WEB-INF/tilesdesign/template.jsp”>
        <put-attribute name=”header” value=”/WEB-INF/tilesdesign/defaultHeader.jsp” />
        <put-attribute name=”menu” value=”/WEB-INF/tilesdesign/defaultMenu.jsp” />
        <put-attribute name=”body” value=”/WEB-INF/jsp/content/about_body.jsp” />
        <put-attribute name=”footer” value=”/WEB-INF/tilesdesign/defaultFooter.jsp” />
    </definition>
</tiles-definitions>



your directory structure should be like:

WEB-INF
 |
 -——jsp
 |    |
 |    -——contents
 |    |       |
 |    |       -——home_body.jsp
 |    |       -——about_body.jsp
 |    |   
 |    |
 |    -——home.jsp
 |    -——about.jsp
 |
 -——tilesdesign
 |    |
 |    -——defaultFooter.jsp
 |    -——defaultHeader.jsp
 |    -——defaultMenu.jsp
 |    -——template.jsp   
 |
 |
 -——lib
 |
 |
 -——TilesConfig.xml
 -——web.xml

spring mvc configuration

Spring MVC
1. Add Dispatcher Servlet to web.xml

e.g.
<servlet>
    <servlet-name>MySpringApp001</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>MySpringApp001</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>




//#########################################################################################################################################
2a. Add mapping of webpages (or “views”) to your controllers in MySpringApp001-servlet.xml
   //to be used by the dispatcher servlet with the “<servlet-name>” hence the filename “MySpringApp001” appended with “-servlet.xml”
   //use the org.springframework.web.servlet.mvc.Controller
e.g.
<bean name=”/hello.htm” class=”springapp.web.HelloController”/>


<———————————————— OR ————————————————>
2b.  Add context support in MySpringApp001-servlet.xml to enable annotations instead of mapping controllers and other POJOs thru XML
  //use the org.springframework.stereotype.Controller
  // @RequestMapping(value=”/mypage.htm”)
 
  Add this to tell Spring to assume that view names are implied by the request URI (/mypage.htm maps to view “mypage”)
  <bean id=”viewNameTranslator” class=”org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator” />
  // @RequestMapping(value=”mypage”)
 
 
e.g.
xmlns:context=”http://www.springframework.org/schema/context”
and
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
and
<context:annotation-config />
<context:component-scan base-package=”springapp.web” />
  //NOTE: adding <mvc:annotation-driven /> will not make section 2a. work!

 


//#########################################################################################################################################
3. Add View Resolver in MySpringApp001-servlet.xml

e.g.
<bean id=”viewResolver”
          class=”org.springframework.web.servlet.view.InternalResourceViewResolver”
          p:prefix=”/WEB-INF/jsp/”
          p:suffix=”.jsp” />

WHEN USING APACHE TILES:
    <bean id=”viewResolver” class=”org.springframework.web.servlet.view.UrlBasedViewResolver”>
        <property name=”viewClass” value=”org.springframework.web.servlet.view.tiles2.TilesView” />
    </bean>
   
    <bean id=”tilesConfigurer” class=”org.springframework.web.servlet.view.tiles2.TilesConfigurer”>
        <property name=”definitions”>
            <list>
                <value>/WEB-INF/tiles-config.xml</value>
            </list>
        </property>
    </bean>

Successful people work 4 hours a day

It sounds too good to be true: Leave work early for greater success on the job.

Psychological Review recently published a study that claims that the key to success is working hard in short bursts of time.

It comes down to focus and choosing specific tasks over multitasking and taking breaks.

The study found that “deliberate” four-hour violin rehearsals accomplished more than seven-hour sessions of steady practice. The best performers set specific goals, practiced with greater intensity for shorter periods of time, and took planned breaks.

The study graphed their hours of productivity, noting that the most intense periods of work were before noon and again after 4. Eventually they found that successful individuals in other professions mirrored this work-less-for-success model.

Business Insider quotes the study:

“While completing a novel, famous authors tend to write only for 4 hours during the morning, leaving the rest of the day for rest and recuperation. Hence successful authors, who can control their work habits and are motivated to optimize their productivity, limit their most important intellectual activity to a fixed daily amount when working on projects requiring long periods of time to complete.”

Tim Ferriss’ bestselling The 4-Hour Workweek made similar conclusions, subscribing to the Pareto principle; 80 percent of outputs come from 20 per cent on inputs.

So instead of slaving away for 12 hours a day, try focused work intervals; your new-found productivity will set you up for success.

Source: http://ca.news.yahoo.com/blogs/good-news/less-success-successful-people-4-hours-day-182803282.html

programming languages stats

C++ tops it.

how sitting is killing you

Sitting is Killing You
Via: Medical Billing And Coding

what a beautiful HTML looks like

cracking the credit card code

How To Choose a Java Web Framework

and the best framework (according to this guy) is.. ItsNat

Microsoft Accuses Google of Anti-Competition

what a payback for the lawsuit against MS’s Bing!

Badass JavaScript: Firefox 4 Launch Day With Brendan Eich

badassjs:

A Minute With Brendan is a great short, mostly weekly podcast produced by the awesome Chris Williams (JSConf organizer) and hosted by Brendan Eich, JavaScript’s creator. As Firefox 4 was just released today, including a much improved JavaScript engine, Brendan talks about it and…

Posted on March 28, 2011

Reblogged from: Badass JavaScript

Source: badassjs

Notes: 10 notes

Top of Page