<$BlogRSDURL$>
  Thursday, October 13, 2005

AJAX on AppFuse

Steps in setting up DWR on AppFuse:

1. Add DWR jar in /lib/dwr-1.0
2. Add to /lib/lib.properties:

#
# DWR - https://dwr.dev.java.net/ (Direct Web Remoting)
#
dwr.version=1.0
dwr.dir=${lib.dir}/dwr-${dwr.version}
dwr.jar=${dwr.dir}/dwr.jar

3. Add to /properties.xml:

<!-- Web -->
<path id="web.compile.classpath">
...
<pathelement location="${dwr.jar}"/>
</path>

4. Add to /build.xml:

<target name="package-web" depends="compile-web,jsp-2" description="Package WAR">
...
<war destfile="${webapp.dist}/${webapp.war}"
webxml="${webapp.target}/WEB-INF/web.xml" compress="true">
...
<lib file="${dwr.jar}"/>
</war>
</target>

5. Add DWR servlet in /metadata/web/servlets.xml:

<!-- dwr servlet -->
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<display-name>DWR Servlet</display-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>

6. Add DWR servlet mapping in /metadata/web/servlet-mappings.xml:

<!-- dwr mapping -->
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

7. Exclude DWR from sitemesh in /web/WEB-INF/classes/decorators.xml:

<excludes>
<pattern>/dwr/*</pattern>
</excludes>

8. Add DWR configuration, /WEB-INF/dwr.xml:

<dwr>
<allow>
<convert converter="bean" match="com.octasoft.fp.*"/>
<create creator="spring" javascript="userManager">
<param name="beanName" value="userManager"/>
<include method="getUser"/>
<include method="getUsers"/>
</create>
</allow>
</dwr>

Here we use DWR provided Spring creator, and utilizes userManager for remoting. Also, we use default-deny policy for the service.

To browse and test DWR-enabled Spring beans: http://server:port/fpweb/dwr/index.html.

Note:
It might be required to delete the existing web.xml in \build\fpweb\WEB-INF\ in order to successfully add in DWR servlet into web.xml.

Use case
Verifying user by username before authentication on loginForm.jsp; on verification, user’s nickname is shown:

<script src="/appfuse/dwr/engine.js" type="text/javascript"></script>
<script src="/appfuse/dwr/util.js" type="text/javascript"></script>
<script src="/appfuse/dwr/interface/userManager.js" type="text/javascript"></script>
<script>
DWREngine.setErrorHandler(doNothing);
var nickname = "";
function doNothing() {
return false;
}
function getNickname() {
if (nickname == "") {
userManager.getUser(popUser,document.loginForm.j_username.value);
document.loginForm.j_password.focus();
return false;
} else {
return validateForm( document.loginForm, false, true, true, false, 1)
}
}

var popUser = function(user) {
if (user == undefined) {
return false;
} else {
DWRUtil.setValue("nick", "Hello, " + user.nickName);
nickname = user.nickName;
}
}
</script>
<form method="post" name="loginForm" id="loginForm"
action="<c:url value="/authorize"/>" onsubmit="return getNickname();">
<div id="nick"></div>
<input name="j_username" type="text" id="j_username"/>
<input name="j_password" type="password" id="j_password"/>
</form>
 

<< Home

Software Culture
  03/01/2004 - 04/01/2004
  04/01/2004 - 05/01/2004
  05/01/2004 - 06/01/2004
  06/01/2004 - 07/01/2004
  08/01/2004 - 09/01/2004
  11/01/2004 - 12/01/2004
  07/01/2005 - 08/01/2005
  09/01/2005 - 10/01/2005
  10/01/2005 - 11/01/2005
  01/01/2006 - 02/01/2006
  03/01/2006 - 04/01/2006
ColdFusion
日常毒藥與養料
  Smart talk always right?
  Drools on AppFuse
  Braille, braille
  可愛提示
  The Dynamic SRC of IMG
  Preferred Locale on AppFuse
  告訴你為什麼程式不 work
  絲綢之路 2000:致命病毒
  AJAX on AppFuse
  1918
  Meet Mr. Writely
  網際網路的最後一頁
  小螞蟻最短篇
  健檢, e檢
  Open source ColdFusion
  八月半個
  自行其是
  Rich DHTML client
  cfspring, seriously
  三百萬民主補給站
  敏督利小插曲
  迷上喬治亞
  說故事
  Where are they?
  宿夢
  An Architect's View
  Martin Fowler
  Loud Thinking
  Raible Designs   fullasagoog
Home


Powered by Blogger