Showing posts with label Parancoe. Show all posts
Showing posts with label Parancoe. Show all posts

Thursday, December 11, 2008

Using Tiles 2 in a Prancoe project

First of all add the Tiles dependency to your pom.xml:


<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.1.0</version>
</dependency>


Specify the places of the Tiles configurations and the Tiles view resolver in your parancoe-servlet.xml file:


<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles/defs/default.xml</value>
</list>
</property>
</bean>

<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
<!-- Default values for prefix and suffix
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
-->
</bean>


Add the /WEB-INF/tiles/defs/default.xml file with the definitions of your views:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>

<definition name="template.main" template="/WEB-INF/tiles/templates/main.jsp">
<put-attribute name="header" value="/WEB-INF/jsp/header.jsp"/>
<put-attribute name="menu" value="/WEB-INF/jsp/menu.jsp"/>
<put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp"/>
</definition>

<definition name="login" extends="template.main">
<put-attribute name="main" value="/WEB-INF/jsp/login.jsp"/>
</definition>

<definition name="admin/conf" extends="template.main">
<put-attribute name="main" value="/WEB-INF/jsp/admin/conf.jsp"/>
</definition>

<definition name="admin/index" extends="template.main">
<put-attribute name="main" value="/WEB-INF/jsp/admin/index.jsp"/>
</definition>

<definition name="admin/logs" extends="template.main">
<put-attribute name="main" value="/WEB-INF/jsp/admin/logs.jsp"/>
</definition>

<definition name="admin/spring" extends="template.main">
<put-attribute name="main" value="/WEB-INF/jsp/admin/spring.jsp"/>
</definition>

<definition name="admin/users/list" extends="template.main">
<put-attribute name="main" value="/WEB-INF/jsp/admin/users/list.jsp"/>
</definition>

<definition name="admin/users/edit" extends="template.main">
<put-attribute name="main" value="/WEB-INF/jsp/admin/users/edit.jsp"/>
</definition>

<definition name="message" extends="template.main">
<put-attribute name="main" value="/WEB-INF/jsp/message.jsp"/>
</definition>

<definition name="genericError" extends="template.main">
<put-attribute name="main" value="/WEB-INF/jsp/genericError.jsp"/>
</definition>

<definition name="accessDenied" extends="template.main">
<put-attribute name="main" value="/WEB-INF/jsp/accessDenied.jsp"/>
</definition>

<definition name="welcome" extends="template.main">
<put-attribute name="main" value="/WEB-INF/jsp/welcome.jsp"/>
</definition>

<definition name="404" extends="template.main">
<put-attribute name="main" value="/WEB-INF/jsp/404.jsp"/>
</definition>

<definition name="500" extends="template.main">
<put-attribute name="main" value="/WEB-INF/jsp/500.jsp"/>
</definition>

</tiles-definitions>


Add the template in /WEB-INF/tiles/templates/main.jsp:


<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ include file="/WEB-INF/jsp/common.jspf" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/WEB-INF/jsp/head.jspf" %>
</head>
<body>
<div id="nonFooter">
<tiles:insertAttribute name="header"/>
<div id="content">
<div id="content_main">
<tiles:insertAttribute name="main"/>
</div>
<tiles:insertAttribute name="menu"/>
</div>
</div>
<tiles:insertAttribute name="footer"/>
</body>
</html>


Now You can simplify your JSP pages, removing from them all the layout-related parts. For example the welcome page (/WEB-INF/jsp/welcome.jsp) was:


<%@ include file="common.jspf" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="head.jspf" %>
</head>
<body>
<div id="nonFooter">
<jsp:include page="header.jsp"/>
<div id="content">
<div id="content_main">
<c:choose>
<c:when test="${requestScope.lang eq 'it'}">
Questa è l'applicazione template per il framework
<a href="http://wwww.parancoe.org">Parancoe</a>.<br />
<br />
Da questo punto di partenza puoi iniziare a costruire la
tua nuova applicazione, sfruttando tutti i benefici che
derivano dall'uso di Parancoe.<br />
<br />
Per maggiori informazioni visita il sito di Parancoe:<br />
<br />
<a href="http://wwww.parancoe.org">http://wwww.parancoe.org</a>.<br />
</c:when>
<c:otherwise>
This is the template application of the
<a href="http://wwww.parancoe.org">Parancoe</a> framework.<br />
<br />
From this starting point you can build your own application,
with all benefits of the using of the Parancoe Framework.<br />
<br />
For more infos, visit the Parancoe framework Web site:<br />
<br />
<a href="http://wwww.parancoe.org">http://wwww.parancoe.org</a>.<br />
</c:otherwise>
</c:choose>
</div>
<jsp:include page="menu.jsp"/>
</div>
</div>
<jsp:include page="footer.jsp"/>
</body>
</html>


Now it's just:


<%@ include file="/WEB-INF/jsp/common.jspf" %>
<c:choose>
<c:when test="${requestScope.lang eq 'it'}">
Questa è l'applicazione template per il framework
<a href="http://wwww.parancoe.org">Parancoe</a>.<br />
<br />
Da questo punto di partenza puoi iniziare a costruire la
tua nuova applicazione, sfruttando tutti i benefici che
derivano dall'uso di Parancoe.<br />
<br />
Per maggiori informazioni visita il sito di Parancoe:<br />
<br />
<a href="http://wwww.parancoe.org">http://wwww.parancoe.org</a>.<br />
</c:when>
<c:otherwise>
This is the template application of the
<a href="http://wwww.parancoe.org">Parancoe</a> framework.<br />
<br />
From this starting point you can build your own application,
with all benefits of the using of the Parancoe Framework.<br />
<br />
For more infos, visit the Parancoe framework Web site:<br />
<br />
<a href="http://wwww.parancoe.org">http://wwww.parancoe.org</a>.<br />
</c:otherwise>
</c:choose>

Thursday, November 13, 2008

Building an AJAX chat with Parancoe and DWR

The AJAX integration through DWR 3 is not the main feature in Parancoe, but it's easy and funny. Let's see how simple is building a Web chat.

Starting from a project generated with Maven using the Parancoe Web Archetype, you need to add the Parancoe DWR Plugin to the dependencies in your pom.xml:


<dependency>
<groupId>org.parancoe</groupId>
<artifactId>parancoe-plugin-dwr</artifactId>
<version>2.0.2</version>
</dependency>


Then add the /dwr/* pattern to the mapping of the parancoe servlet in your web.xml.

Now DWR is ready to be used in your application. You check it building and deploying your application, and pointing your browser to <your_base_address>/dwr/index.html. You should see the DWR Test Page.

Then add a class with methods (a single method in this example) that will be invoked through AJAX:


package com.mycompany.testapp.ajax;

import org.directwebremoting.Browser;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.ui.dwr.Util;
import org.springframework.stereotype.Component;

@Component
@RemoteProxy(name = "chat")
public class Chat {

@RemoteMethod
public void send(final String nickname, final String message) {
Browser.withCurrentPage(new Runnable() {
public void run() {
Util.addRows("chatLog", new String[][]{{nickname, message}});
}
});
}
}


Simple, isn't it? ...but powerful. When invoked that method will add a row to the table with id chatLog, in all browsers that are visualizing that page.

Let's see the page chat.jsp in which that method is invoked:


<%@ include file="WEB-INF/jsp/common.jspf" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
<%@ include file="WEB-INF/jsp/head.jspf" %>
<script src="${cp}/dwr/interface/chat.js" type="text/javascript"/>
<script src="${cp}/dwr/engine.js" type="text/javascript" />
<script src="${cp}/dwr/util.js" type="text/javascript" />
<title>Parancoe DWR chat</title>
</head>
<body>
<h1>DWR Chat</h1>

<table id="chatLog">
<thead>
<tr><th>Nickname</th><th>Message</th></tr>
</thead>
<tbody> </tbody>
</table>

<form id="chatForm" method="post" action="/sendMessage">
Nickname: <input id="nickname" type="text" /><br/>
Say: <input id="say" type="text" /><br/>
<input type="submit">
</form>

<script type="text/javascript">
function bindUI() {
$('chatForm').observe('submit', chatSubmit);
}

function chatSubmit(event) {
event.stop();
chat.send($F('nickname'), $F('say'));
}

dwr.engine.setActiveReverseAjax(true);
document.observe('dom:loaded', bindUI);
</script>
</body>
</html>


In your parancoe-servlet.xml file add the following configuration for enabling the active reverse AJAX in DWR:






Build and deploy your application. Open multiple windows of your browser(s) to <your_base_address>/chat.jsp, and start chatting:



Have fun with Parancoe!

Saturday, November 8, 2008

Parancoe 2.0

Last week the Parancoe Team (me and other smart people :) ) released the version 2.0 of the Parancoe meta-framework. With this release Parancoe achieved a great level of maturity.

In the next weeks, starting with this post, I will demonstrate how easy and pleasant is to develop applications with Parancoe.

First demonstration! :) How difficult is to start a new project with Parancoe? No difficult at all. Install Maven and type the following command:

mvn archetype:create -DarchetypeGroupId=org.parancoe \
-DarchetypeArtifactId=parancoe-webarchetype \
-DarchetypeVersion=2.0.1 \
-DgroupId=com.mycompany \
-DartifactId=testApp \
-DpackageName=com.mycompany.testapp

It will generate a new complete project ready for your next development. I repeat, complete, the new application is already working, you can build and deploy it on your application server and use it. You'll see a simple layout, administrative tasks, debug information in page (when deployed in development mode), user authentication and authorization, user management.

With a good IDE :) the start-up task is even easier. Watch this my previous, still valid, screen-cast.

Don't miss to read the new Parancoe Reference Guide, both in HTML and in PDF.

Have fun!

Thursday, March 20, 2008

Start a new Web project with the Parancoe Web meta-framework and NetBeans 6.1

Starting new Web project using the Parancoe meta-framework is very easy and fast. Even more if you are using a good IDE. Watch at this screencast, in which I create a new project with Parancoe and NetBeans 6.1.










Download the screen cast at the maximum resolution.

Monday, October 15, 2007

JavaDay in Turin

Next Saturday I'll speak at the JavaDay in Turin.

My presentation will show that the following code can be a fully functional Data Access Object (DAO):

Note, not any other code or configuration to write, just that interface: NO code...NO bugs...more FUN! :)

See you in Turin...

(If you can't...look at the Parancoe site)

Monday, September 3, 2007

JUG Events

Estate abbastanza produttiva...sole, mare, spiaggia, ombrellone...e sviluppo di JUG Events!

Cos'è JUG Events? E' soprattutto la scusa per sperimentare con Parancoe, quindi principalmente con Hibernate/JPA, Spring, Spring MVC e Maven. Ma anche con JCaptcha, JavaMail, Velocity, Plextile, e chi più ne ha, più ne metta.

A parte la sperimentazione, che comunque ha portato nuove idee e sviluppo per Parancoe, l'applicazione può essere utile, quindi l'ho messa online a disposizione dei JUG che vorranno usarla:

www.jugevents.org

Se invece volete studiarne i sorgenti, li trovate nel repository Subversion di Parancoe.

Aggiornamento: JUG Events ha ora un proprio progetto separato per lo sviluppo su Google Code. jugevents.googlecode.com