<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>auJava</title>
	<atom:link href="http://aujava.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://aujava.wordpress.com</link>
	<description>Australian java weblog</description>
	<lastBuildDate>Mon, 14 Nov 2011 07:56:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='aujava.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>auJava</title>
		<link>http://aujava.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://aujava.wordpress.com/osd.xml" title="auJava" />
	<atom:link rel='hub' href='http://aujava.wordpress.com/?pushpress=hub'/>
		<item>
		<title>blog moved to blog.aujava.com</title>
		<link>http://aujava.wordpress.com/2007/04/24/blog-moved-to-blogaujavacom/</link>
		<comments>http://aujava.wordpress.com/2007/04/24/blog-moved-to-blogaujavacom/#comments</comments>
		<pubDate>Tue, 24 Apr 2007 10:43:53 +0000</pubDate>
		<dc:creator>Robert Sayfullin</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://aujava.wordpress.com/2007/04/24/blog-moved-to-blogaujavacom/</guid>
		<description><![CDATA[Recently I have moved the blog to better place   Please update your bookmarks.  blog.aujava.com<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=34&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I have moved the blog to better place <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Please update your bookmarks.  <a href="http://blog.aujava.com" title="blog.aujava.com">blog.aujava.com</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aujava.wordpress.com/34/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aujava.wordpress.com/34/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aujava.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aujava.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aujava.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aujava.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aujava.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aujava.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aujava.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aujava.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aujava.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aujava.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aujava.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aujava.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aujava.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aujava.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=34&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aujava.wordpress.com/2007/04/24/blog-moved-to-blogaujavacom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8dd7a2f17682913d8e7e8797b4647c6f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aujava</media:title>
		</media:content>
	</item>
		<item>
		<title>Generic OGNL Controller without Spring WebFlow</title>
		<link>http://aujava.wordpress.com/2007/01/22/generic-ognl-controller-without-spring-webflow/</link>
		<comments>http://aujava.wordpress.com/2007/01/22/generic-ognl-controller-without-spring-webflow/#comments</comments>
		<pubDate>Mon, 22 Jan 2007 03:22:03 +0000</pubDate>
		<dc:creator>Robert Sayfullin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://aujava.wordpress.com/2007/01/22/generic-ognl-controller-without-spring-webflow/</guid>
		<description><![CDATA[While working on various web projects many times I felt guilty for writing controllers that perform one-two rows of the code. It must be easier way! And when I read and tried Spring WebFlow I really liked their approach for defining how to call methods on any exposed bean. It is what I was looking [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=26&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>While working on various web projects many times I felt guilty for writing controllers that perform one-two rows of the code.<br />
It must be easier way! And when I read and tried Spring WebFlow I really liked their approach for defining how to call methods on any exposed bean.<br />
It is what I was looking for. Simple things made easy inside the xml config:</p>
<pre>
 &lt;bean-action bean="cartController" method="changeQuantities"&gt;

 	&lt;method-arguments&gt;&lt;argument expression="flowScope.viewCommand"/&gt;&lt;/method-arguments&gt;

 	&lt;method-result name="viewCommand" scope="flow"/&gt;

 &lt;/bean-action&gt;</pre>
<p>However Spring WebFlow has many aspects that would stop you from using it for entire site. Click-around navigation and SWF do not play well together.<br />
So what I need is ability to define OGNL expression in Spring coonfig without using SWF. What looked scarry on first sight turned to be extremely easy task.<br />
I did some prototyping of idea and here is what I got in spring config file:</p>
<pre>
 &lt;bean id="profileView" class="com.cochlear.mcc.web.GenericFormController"&gt;

 	&lt;property name="formView" value="profileView"/&gt;

 	&lt;property name="manager"&gt;&lt;ref bean="profileManager"/&gt;&lt;/property&gt;

 	&lt;property name="viewScript"&gt;&lt;value&gt;manager.getProfile()&lt;/value&gt;&lt;/property&gt;

 &lt;/bean&gt;

 &lt;bean id="profileForm" class="com.cochlear.mcc.web.GenericFormController"&gt;

 	&lt;property name="formView" value="profileForm"/&gt;

 	&lt;property name="manager"&gt;&lt;ref bean="profileManager"/&gt;&lt;/property&gt;

 	&lt;property name="modelClass"&gt;&lt;value&gt;com.cochlear.mcc.profile.model.ProfileDTO&lt;/value&gt;&lt;/property&gt;

 	&lt;property name="viewScript"&gt;&lt;value&gt;manager.getProfile()&lt;/value&gt;&lt;/property&gt;

 	&lt;property name="postScript"&gt;&lt;value&gt;manager.updateProfile(#object)&lt;/value&gt;&lt;/property&gt;

 	&lt;property name="successView" value="redirect:profile.view"/&gt;

 &lt;/bean&gt;</pre>
<p>Not as clear as in SWF maybe but enough to prove the idea. It is concise, it does the job. You do not have to write FormActions for trivial things.<br />
Here is what I have in GenericFormController:</p>
<pre>public class GenericFormController extends SimpleFormController{

 protected Object manager;

 protected String viewScript;

 protected String postScript;

protected Object formBackingObject(HttpServletRequest request) throws ServletException, InstantiationException, IllegalAccessException {

 	try {

     	if(StringUtils.hasText(viewScript)){

 			OgnlContext context= new OgnlContext();

 			populateOgnlContextCommon(context, request);

 			Object expr = Ognl.parseExpression(viewScript);

 			Object res=Ognl.getValue(expr, context, this);

 			return res;

     	}else{

     		return getCommandClass().newInstance();

     	}

 	} catch (OgnlException e) {

 		e.printStackTrace();

 		throw new ServletException(e);

 	}

    }

protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,

                                    Object commandObject, BindException errors) throws Exception {

Object command = getCommandClass().cast(commandObject);

 	try {

     	if(StringUtils.hasText(postScript)){

 			OgnlContext context= new OgnlContext();

 			context.put("command", command);

 			populateOgnlContextCommon(context, request);

 			Object expr = Ognl.parseExpression(postScript);

 			Ognl.getValue(expr, context, this);

     	}else{

     		throw new ServletException("No postScript specified");

     	}

 	} catch (Exception e) {

 		errors.reject(null, "Error:"+e.getMessage());

 		return showForm(request, errors, getFormView());

 	}

return new ModelAndView(getSuccessView());

    }

protected void populateOgnlContextCommon(OgnlContext context, HttpServletRequest request){

 	  context.put("request", request);

 	  context.put("session", request.getSession());

 	  context.put("user", SecurityContextHolder.getContext().getAuthentication().getPrincipal());

    }

// Getters and Setters here ..

 // ...

}</pre>
<p>When I have time I will do something more production grade. For now I just glad to know that it is achievable and quite simple actualy.</p>
<p><a href="http://digg.com/submit?phase=3&amp;url=http://aujava.wordpress.com/2007/01/22/generic-ognl-controller-without-spring-webflow/" title="DiggIt">DiggIt</a> | <a href="http://del.icio.us/post?url=http://aujava.wordpress.com/2007/01/22/generic-ognl-controller-without-spring-webflow/&amp;title=Generic%20OGNL%20Controller%20without%20Spring%20WebFlow">del.icio.us</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aujava.wordpress.com/26/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aujava.wordpress.com/26/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aujava.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aujava.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aujava.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aujava.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aujava.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aujava.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aujava.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aujava.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aujava.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aujava.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aujava.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aujava.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aujava.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aujava.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=26&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aujava.wordpress.com/2007/01/22/generic-ognl-controller-without-spring-webflow/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8dd7a2f17682913d8e7e8797b4647c6f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aujava</media:title>
		</media:content>
	</item>
		<item>
		<title>Runing Tomcat as Linux service</title>
		<link>http://aujava.wordpress.com/2007/01/21/runing-tomcat-as-linux-service/</link>
		<comments>http://aujava.wordpress.com/2007/01/21/runing-tomcat-as-linux-service/#comments</comments>
		<pubDate>Sun, 21 Jan 2007 22:06:52 +0000</pubDate>
		<dc:creator>Robert Sayfullin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://aujava.wordpress.com/2007/01/21/runing-tomcat-as-linux-service/</guid>
		<description><![CDATA[Not big deal but I am bit tired to google for this script each time I setup new box. Now I know where to get it without spending two valuable extra minutes to google. First create /etc/rc.d/init.d/tomcatd : #!/bin/bash # # Startup script for Tomcat # # chkconfig: 345 84 16 # description: Tomcat jakarta [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=33&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Not big deal but I am bit tired to google for this script each time I setup new box. Now I know where to get it without spending two valuable extra minutes to google. First create /etc/rc.d/init.d/tomcatd :</p>
<pre>
#!/bin/bash
#
# Startup script for Tomcat
#
# chkconfig: 345 84 16
# description: Tomcat jakarta JSP server
TOMCAT_HOME=/usr/share/apache-tomcat-5.5.20
TOMCAT_START=$TOMCAT_HOME/bin/startup.sh
TOMCAT_STOP=$TOMCAT_HOME/bin/shutdown.sh
#Necessary environment variables
export JAVA_HOME=”/usr/share/jdk1.5.0_10?
export CATALINA_HOME=”/usr/share/apache-tomcat-5.5.20?
#export LD_KERNEL_ASSUME=”2.2.5?
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = “no” ] &amp;&amp; exit 0
#Check for tomcat script
if [ ! -f $TOMCAT_HOME/bin/catalina.sh ]
then
    echo “Tomcat not available…”
    exit
fi
start() {
    echo -n “Starting Tomcat: “
    su - tomcat -c $TOMCAT_START
    echo
    touch /var/lock/subsys/tomcatd
# We may need to sleep here so it will be up for apache
    sleep 3
#Instead should check to see if apache is up by looking for httpd.pid
}
stop() {
    echo -n $”Shutting down Tomcat: “
    su - tomcat -c $TOMCAT_STOP
    rm -f /var/lock/subsys/tomcatd
    echo
}
status() {
    ps ax –width=1000 | grep “[o]rg.apache.catalina.startup.Bootstrap start” | awk ‘{printf $1 ” “}’ | wc | awk ‘{print $2}’ &gt; /tmp/tomcat_process_count.txt
   read line</pre>
<p>Add user tomcat. Please note that it is normal user with his own home. Many times it was very useful.</p>
<pre>
adduser tomcat</pre>
<p>Set JAVA_HOME for all users in /etc/profile.d/java.sh . When we run ’su &#8211; tomcat’ this script will set up our environment:</p>
<pre>
export JAVA_HOME=/usr/share/jdk1.5.0_10</pre>
<p>Give enough permissions to tomacat:</p>
<pre>
chown tomcat /usr/share/apache-tomcat-5.5.20/ -R</pre>
<p>Now you are able to run tomcat with</p>
<pre>
service tomcatd start</pre>
<p>The last thing is to run it when system boots:</p>
<pre>
chkconfig –add tomcatd
chkconfig tomcatd on</pre>
<p>Done</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aujava.wordpress.com/33/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aujava.wordpress.com/33/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aujava.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aujava.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aujava.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aujava.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aujava.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aujava.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aujava.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aujava.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aujava.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aujava.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aujava.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aujava.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aujava.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aujava.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=33&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aujava.wordpress.com/2007/01/21/runing-tomcat-as-linux-service/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8dd7a2f17682913d8e7e8797b4647c6f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aujava</media:title>
		</media:content>
	</item>
		<item>
		<title>POSTable HTML links</title>
		<link>http://aujava.wordpress.com/2007/01/17/postable-html-links/</link>
		<comments>http://aujava.wordpress.com/2007/01/17/postable-html-links/#comments</comments>
		<pubDate>Wed, 17 Jan 2007 02:19:31 +0000</pubDate>
		<dc:creator>Robert Sayfullin</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://aujava.wordpress.com/2007/01/17/postable-html-links/</guid>
		<description><![CDATA[When building web sites you often have to produce POST request on user&#8217;s actions. Many times without having user &#8211; editable form fields. Server just expects you to send POST. The standard solution is to make hidden form, hardcode some fields value and dynamically populate other values when user presses submit button. It does the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=28&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When building web sites you often have to produce POST request on user&#8217;s actions. Many times without having user &#8211; editable form fields. Server just expects you to send POST. The standard solution is to make hidden form, hardcode some fields value and dynamically populate other values when user presses submit button. It does the job. But the code is spoiled with these pseudo forms and, I believe, you never gonna like it.</p>
<p>There is other approach that is much more concise and programmer friendly (tm:) . The trick is to construct and submit form on-the-fly. Let&#8217;s start with JavaScript function that exploits Prototype:<br />
<span id="more-28"></span></p>
<pre>
// Expects URL with queryString as param href
function createAndSubmitDynamicForm(href){
	try{
		var lex1 = href.split('?');
		var action= lex1[0];
		var qstr = lex1[1];

		var insertion="&lt;form id='dynamicPostForm' method='POST' action='"+action+"'&gt;";
		if(qstr != null) {
			var params = qstr.split('&amp;');
			(params).each(function(param){
				var keyValue = param.split('=');
				var name = keyValue[0];
				var value = keyValue[1];
				insertion += "&lt;input type='hidden' name='"+name+"' value='"+value+"'/&gt;";
			});
		}
		insertion += "&lt;/form&gt;";

		new Insertion.After($('anyDivAtTheEndOfBody'), insertion);
		$('dynamicPostForm').submit();
	}catch(e){
		alert("Error"+e);
	}
}</pre>
<p>Code is pretty much self explanatory hence not optimal. You can easily make it twice shorter if you need. Now is time to make a JSP tag that will expose our function in a nice way.</p>
<pre>

&lt;%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %&gt;
&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;

&lt;%@ attribute name="code" required="true"%&gt;
&lt;%@ attribute name="href" required="true"%&gt;
&lt;%@ attribute name="confirmMessage" required="false"%&gt;
&lt;%@ attribute name="css" required="false"%&gt;
&lt;input type="button"
	   value="&lt;spring:message code="${code}"/&gt;"
	   class="${css}"
	   onclick="&lt;c:if test="${ ! empty confirmMessage}"&gt;if (confirm('&lt;spring:message code="${confirmMessage}"/&gt;')) &lt;/c:if&gt;createAndSubmitDynamicForm('${href}');"/&gt;</pre>
<p>One thing to mention. We can have optional parameter &#8216;confirmMessage&#8217; that will ask user if he really wants to submit the form. It is necessary whenever you place buttons &#8216;Remove&#8217;, &#8216;Delete&#8217;, &#8216;Make-Something-Horrible&#8217; buttons. After plugging you JSP tag you will be able to have on the page something like:</p>
<pre>
&lt;myTag:post href="controller.htm?action=payDebt&amp;from=savingAccount&amp;to=creditAccount&amp;when=now" code="my.localized.button.name"/&gt;</pre>
<p>It is even simpler and better than</p>
<pre>&lt;a href=""&gt;</pre>
<p>HTML tag!</p>
<p>Don&#8217;t thank me. At least yet. There is one more feature. Assume that you want to include really dynamic parameters in this POST. Let say you have number of products on the page and under each product there is &#8216;quanity&#8217; field and &#8216;Add to Cart&#8217; button. Solution is quite simple again. These is updated version of JS function:</p>
<pre>
// Expects URL with queryString as param href. Can have {name} placeholders for values of input fields
function createAndSubmitDynamicForm(href){
	try{
		var lex1 = href.split('?');
		var action= lex1[0];
		var qstr = lex1[1];

		var insertion="&lt;form id='dynamicPostForm' method='POST' action='"+action+"'&gt;";
		if(qstr != null) {
			var params = qstr.split('&amp;');
			(params).each(function(param){
				var keyValue = param.split('=');
				var name = keyValue[0];
				var value = keyValue[1];
				// we can have runtime(js) placeholders in params
				if (value.match("^{w+}$")){
					var fieldName = value.substr(1, value.length-2);
					value = $F(fieldName);
				}
				insertion += "&lt;input type='hidden' name='"+name+"' value='"+value+"'/&gt;";
			});
		}
		insertion += "&lt;/form&gt;";

		new Insertion.After($('anyDivAtTheEndOfBody'), insertion);
		$('dynamicPostForm').submit();
	}catch(e){
		alert("Error"+e);
	}
}</pre>
<p>So now we can have such peace of HTML:</p>
<pre>
...
&lt;input type='text' id='quantity' value='1'/&gt;
&lt;myTag:post href="cartController.htm?action=addToCart&amp;itemId=123&amp;quantity={quantity}" code="add.to.cart"/&gt;
...</pre>
<p>Done.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aujava.wordpress.com/28/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aujava.wordpress.com/28/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aujava.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aujava.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aujava.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aujava.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aujava.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aujava.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aujava.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aujava.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aujava.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aujava.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aujava.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aujava.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aujava.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aujava.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=28&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aujava.wordpress.com/2007/01/17/postable-html-links/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8dd7a2f17682913d8e7e8797b4647c6f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aujava</media:title>
		</media:content>
	</item>
		<item>
		<title>Discovering Spring MVC</title>
		<link>http://aujava.wordpress.com/2006/08/28/discovering-spring-mvc/</link>
		<comments>http://aujava.wordpress.com/2006/08/28/discovering-spring-mvc/#comments</comments>
		<pubDate>Mon, 28 Aug 2006 09:18:50 +0000</pubDate>
		<dc:creator>Robert Sayfullin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">https://aujava.wordpress.com/2006/08/28/discovering-spring-mvc/</guid>
		<description><![CDATA[Spring MVC is not taken seriously jet because of almost absent documentation. For 2.0 version they wrote couple more paragraphs. But still only pages 214-250 devoted to Spring MVC itself. Many features left undocumented. For my recent project I had to build a form having 6 different sets of fields. Depending on selected value in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=23&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Spring MVC is not taken seriously jet because of almost absent documentation. For 2.0 version they wrote couple more paragraphs. But still only pages 214-250 devoted to Spring MVC itself. Many features left undocumented.</p>
<p>For my recent project I had to build a form having 6 different sets of fields. Depending on selected value in combo-box I process specific set. The rest of fields are ignored. That was easy to decide but how to tell Spring no to bind some fields?</p>
<p>One approach is to process input manually disabling automatic binding by overriding supressBinding function:</p>
<pre>protected boolean suppressBinding(HttpServletRequest request) {
  return false;
}</pre>
<p>Will work but leaves whole burden of binding on your shoulders. You do not want that. The other approach is letting Spring know which fields you want to process and which not. Take a look:<br />
<span id="more-23"></span></p>
<pre>protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
  super.initBinder(request, binder);
  if (! isFormSubmission(request))
    return ;
  try {
    String selectedBenefitType = ServletRequestUtils.getRequiredStringParameter(request, "benefitType");
    List disallowedFields = new ArrayList();
    //disallow processing of any field that do not belong to currently selected benefit
    for (String benefitType:BaseBenefit.benefitTypes){
      if (! selectedBenefitType.equalsIgnoreCase(benefitType)){
        String fieldMask = StringUtils.uncapitalize(benefitType)+".*";
        disallowedFields.add(fieldMask);
      }
    }
    binder.setDisallowedFields(disallowedFields.toArray(new String[disallowedFields.size()]));
    binder.setRequiredFields(new String[]{"benefitType", "sinceDate", "untilDate"});
  } catch (ServletRequestBindingException e) {
    logger.error(e.getMessage(), e);
    throw new RuntimeException(e);
  }
}</pre>
<p>Here we pass list of unwanted fields to binder.setDisallowedFields and that is it. Those fields will not be bound and you will not receive &#8216;Can not convert field someDate to java.util.Date&#8217; for fields that are not wanted, not filled and even hidden on the form. As you have probably noticed You can use wild-cards in field names.</p>
<p>I like Spring a lot. And I use it in every single Java project I do. So take my advice. When you want to use Spring MVC seriously, the first step is to tear away Spring MVC paragraph from documentation so you do not pretend that you have it at all. Read an API and dig into source code. Soon you will discover that your web-tier improved a lot.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aujava.wordpress.com/23/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aujava.wordpress.com/23/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aujava.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aujava.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aujava.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aujava.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aujava.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aujava.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aujava.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aujava.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aujava.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aujava.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aujava.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aujava.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aujava.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aujava.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=23&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aujava.wordpress.com/2006/08/28/discovering-spring-mvc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8dd7a2f17682913d8e7e8797b4647c6f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aujava</media:title>
		</media:content>
	</item>
		<item>
		<title>Ascon:use-case diagram</title>
		<link>http://aujava.wordpress.com/2006/08/20/asconuse-case-diagram/</link>
		<comments>http://aujava.wordpress.com/2006/08/20/asconuse-case-diagram/#comments</comments>
		<pubDate>Sun, 20 Aug 2006 07:51:03 +0000</pubDate>
		<dc:creator>Robert Sayfullin</dc:creator>
				<category><![CDATA[Ascon]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://aujava.wordpress.com/2006/08/20/asconuse-case-diagram/</guid>
		<description><![CDATA[Using of Ascon only available for registered users. We need simplest possible register and login functionality. Ascon user interface mainly provide functionality for managing(CRUD) user&#8217;s addressbook and CallJobs. In list of CallJobs user should also have ability to see kind a report for completed jobs. When CallJob executed we need to place a call and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=22&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Using of Ascon only available for registered users.  We need simplest possible register and login functionality.</p>
<p align="left"><a href="http://aujava.files.wordpress.com/2006/08/uml_usecase1.jpg" class="imagelink" title="UML_ascon_usecase"><img src="http://aujava.files.wordpress.com/2006/08/uml_usecase1.thumbnail.jpg?w=450" alt="UML_ascon_usecase" align="left" /></a>Ascon user interface mainly provide functionality for managing(CRUD) user&#8217;s addressbook and CallJobs. In list of CallJobs user should also have ability to see kind a report for completed jobs.</p>
<p>When CallJob executed we need to place a call and when answered read out the text of message. After that JobCall is considered as completed. If nobody answers the call we mark it as dismissed. In next versions we might want to introduce &#8220;redial schedule&#8221; for repeating unaswered calls until completion.</p>
<p><a href="void()" id="I18"></a> For incoming calls we are going to have conventional IVR service with arbitrary dialog.</p>
<p>Operator has all functionality as normal user, report for all users, report for all JobCalls and ability to manage Carriers.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aujava.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aujava.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aujava.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aujava.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aujava.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aujava.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aujava.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aujava.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aujava.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aujava.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aujava.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aujava.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aujava.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aujava.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aujava.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aujava.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=22&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aujava.wordpress.com/2006/08/20/asconuse-case-diagram/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8dd7a2f17682913d8e7e8797b4647c6f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aujava</media:title>
		</media:content>

		<media:content url="http://aujava.files.wordpress.com/2006/08/uml_usecase1.thumbnail.jpg" medium="image">
			<media:title type="html">UML_ascon_usecase</media:title>
		</media:content>
	</item>
		<item>
		<title>Improvement of JSON to JAVA marshalling with JSON-RPC</title>
		<link>http://aujava.wordpress.com/2006/08/16/improvement-of-json-to-java-marshalling-with-json-rpc/</link>
		<comments>http://aujava.wordpress.com/2006/08/16/improvement-of-json-to-java-marshalling-with-json-rpc/#comments</comments>
		<pubDate>Wed, 16 Aug 2006 04:46:21 +0000</pubDate>
		<dc:creator>Robert Sayfullin</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">https://aujava.wordpress.com/2006/08/16/improvement-of-json-to-java-marshalling-with-json-rpc/</guid>
		<description><![CDATA[During debugging one of my porjects I&#8217;ve spoted the following code in BeanSerializer.java from JSON-RPC library: public Object unmarshall(SerializerState state, Class clazz, Object o) ... Method setMethod = (Method)bd.writableProps.get(field); if(setMethod != null) { ... setMethod.invoke(instance, invokeArgs); ... } The class is responsible of transforming Json notation to your Java Bean. Looking at code I realised [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=16&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>During debugging one of my porjects I&#8217;ve spoted the following code in<em> BeanSerializer.java</em> from JSON-RPC library:</p>
<pre><code>
public Object unmarshall(SerializerState state, Class clazz, Object o)
...
Method setMethod = (Method)bd.writableProps.get(field);
if(setMethod != null) {
</code><code>    </code><code>...
</code><code>    </code><code>setMethod.invoke(instance, invokeArgs);
</code><code>    </code><code>...
}
</code></pre>
<p>The class is responsible of transforming Json notation to your Java Bean. Looking at code I realised that when no setter is present for field(or you mistyped field name in JSON) nothing happens. Nothing is set on the Bean obviously and no exception is thrown! Is some situation it makes sence. Silently dropping of absent fields is nice feature when you write backward compatible code or similar. But in most cases you want to rise an exception when field name does not match to Java bean fields. So I suggest to modify this code like following:<br />
<span id="more-16"></span></p>
<pre><code>
while(i.hasNext()) {
    String field = (String)i.next();
    Method setMethod = (Method)bd.writableProps.get(field);
    if(setMethod != null) {
	try {
	    Class param[] = setMethod.getParameterTypes();
	    fieldVal = ser.unmarshall(state, param[0], jso.get(field));
	} catch (UnmarshallException e) {
	    throw new UnmarshallException("bean " + clazz.getName() + " on field "+ field +
					  " " + e.getMessage());
	}
	if(ser.isDebug())
	    log.fine("invoking " + setMethod.getName() +
		     "(" + fieldVal + ")");
	invokeArgs[0] = fieldVal;
	try {
	    setMethod.invoke(instance, invokeArgs);
	} catch (Throwable e) {
	    if(e instanceof InvocationTargetException)
		e = ((InvocationTargetException)e).getTargetException();
	    throw new UnmarshallException("bean " + clazz.getName() + "can't invoke " +
				 setMethod.getName() + ": " + e.getMessage());
	}
    }<strong>else{
    	if( ! "javaClass".equals(field)){
 		throw new RuntimeException("Class "+clazz +" does not have setter for field " + field +"!");
   	}//if
</strong></code><code>    </code><code><strong>}</strong>
</code></pre>
<p>The next step would be to introduce <strong>lenientMarshalling</strong> configuration parameter for JSON-RPC bridge that controll strictness of marshalling operations.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aujava.wordpress.com/16/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aujava.wordpress.com/16/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aujava.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aujava.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aujava.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aujava.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aujava.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aujava.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aujava.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aujava.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aujava.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aujava.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aujava.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aujava.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aujava.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aujava.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=16&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aujava.wordpress.com/2006/08/16/improvement-of-json-to-java-marshalling-with-json-rpc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8dd7a2f17682913d8e7e8797b4647c6f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aujava</media:title>
		</media:content>
	</item>
		<item>
		<title>Watchdog for tomcat</title>
		<link>http://aujava.wordpress.com/2006/08/16/watchdog-for-tomcat/</link>
		<comments>http://aujava.wordpress.com/2006/08/16/watchdog-for-tomcat/#comments</comments>
		<pubDate>Wed, 16 Aug 2006 00:39:38 +0000</pubDate>
		<dc:creator>Robert Sayfullin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">https://aujava.wordpress.com/2006/08/16/watchdog-for-tomcat/</guid>
		<description><![CDATA[Here is just short script that restarts tomcat when it wrizes. It happens to our prod during peak load. You need to place inder webapps/ROOT directory a file isalive.html with one word &#8216;YES&#8217; inside. Or alternatively modify a script and access default index.jsp. #!/bin/sh HOST=127.0.0.1 PORT=8080 #infinite loop while [ 1 ] do #try to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=15&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is just short script that restarts tomcat when it wrizes. It happens to our prod during peak load. You need to place inder <i>webapps/ROOT</i> directory a file <i>isalive.html</i> with one word &#8216;YES&#8217; inside. Or alternatively modify a script and access default<i> index.jsp</i>.</p>
<pre><code>

#!/bin/sh
HOST=127.0.0.1
PORT=8080

#infinite loop
while [ 1 ]
do
	#try to access tomcat's page
	RES=`wget -O - -o /dev/null --proxy=off http://${HOST}:${PORT}/isalive.html | awk '{ print $1 }'`
	echo got ${RES}
	#decide on reply
	if [ "$RES" = "YES" ]
	then
		echo tomcat is responding on $HOST:$PORT
	else
		echo tomcat seems to be dead.
		echo Killing...
		for thepin in `ps -Af | grep -v grep | grep tomcat | grep catalina | awk '{ print $2 }'`
		do
			kill -9 ${thepin}
		done
		echo Starting...
		sudo -u tomcat /usr/local/tomcat/bin/startup.sh
	fi

sleep 60
done

</code></pre>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aujava.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aujava.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aujava.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aujava.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aujava.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aujava.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aujava.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aujava.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aujava.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aujava.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aujava.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aujava.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aujava.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aujava.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aujava.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aujava.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=15&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aujava.wordpress.com/2006/08/16/watchdog-for-tomcat/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8dd7a2f17682913d8e7e8797b4647c6f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aujava</media:title>
		</media:content>
	</item>
		<item>
		<title>Java technologies popularity in Sydney</title>
		<link>http://aujava.wordpress.com/2006/08/13/java-technologies-popularity-in-sydney/</link>
		<comments>http://aujava.wordpress.com/2006/08/13/java-technologies-popularity-in-sydney/#comments</comments>
		<pubDate>Sun, 13 Aug 2006 13:39:32 +0000</pubDate>
		<dc:creator>Robert Sayfullin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Job]]></category>

		<guid isPermaLink="false">https://aujava.wordpress.com/2006/08/13/java-technologies-popularity-in-sydney/</guid>
		<description><![CDATA[Here is just some numbers from jobserve.com.au. All keywords were prefixed with Sydney AND Java AND statement. The search for Sydney AND Java only gives 500 matching jobs. AppServer: WebSphere &#8211; 56 WebLogic &#8211; 47 Tomcat &#8211; 41 JBoss &#8211; 32 Sun -21 JRun &#8211; 3 GlassFish &#8211; 0 Geronimo &#8211; 0 DataBase: Oracle &#8211; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=14&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src="http://aujava.files.wordpress.com/2006/08/aujava_logo.gif?w=450" alt="AuJava logo" align="left" /></p>
<p>Here is just some numbers from jobserve.com.au. All keywords were prefixed with <span>Sydney AND Java AND</span> statement. The search for <span>Sydney AND Java</span> only gives 500 matching jobs.<br />
AppServer:</p>
<ol>
<li>WebSphere &#8211; 56</li>
<li>WebLogic &#8211; 47</li>
<li>Tomcat &#8211; 41</li>
<li>JBoss &#8211; 32</li>
<li>Sun -21</li>
<li>JRun &#8211; 3</li>
<li>GlassFish &#8211; 0</li>
<li>Geronimo &#8211; 0</li>
</ol>
<p><span id="more-14"></span>DataBase:</p>
<ol>
<li>Oracle &#8211; 146</li>
<li>Sybase &#8211; 69</li>
<li>DB2 &#8211; 24</li>
<li>MySql &#8211; 18</li>
<li>MS Sql &#8211; 10</li>
<li>Postgres &#8211; 1</li>
<li>Derby &#8211; 0</li>
</ol>
<p>Mapping:</p>
<ol>
<li>Hibernate &#8211; 85</li>
<li>JDBC &#8211; 26</li>
<li>JDO &#8211; 4</li>
<li>Toplink &#8211; 0</li>
</ol>
<p>MVC and templating:</p>
<ol>
<li>STRUTS &#8211; 75</li>
<li>Swing &#8211; 10</li>
<li>Spring MVC &#8211; 9</li>
<li>JSF &#8211; 8</li>
<li>Tapestry &#8211; 4</li>
<li>Sitemesh &#8211; 0</li>
<li>Tiles &#8211; 0</li>
<li>RIFE &#8211; 0</li>
</ol>
<p>OS:</p>
<ol>
<li>UNIX &#8211; 110</li>
<li>Microsoft  &#8211; 55</li>
<li>Solaris &#8211; 37</li>
<li>Linux &#8211; 32</li>
</ol>
<p>Scripting</p>
<ol>
<li>Perl &#8211; 47</li>
<li>Shell &#8211; 34</li>
<li>JavaScript &#8211; 33</li>
</ol>
<p>Build, testing, etc</p>
<ul>
<li>JUnit &#8211; 31</li>
<li>ant &#8211; 22</li>
<li>maven -4</li>
<li>continuum &#8211; 1</li>
</ul>
<p><span>Frameworks, technologies and other TLA:</span></p>
<ul>
<li>Spring &#8211; 66</li>
<li>SDLC  &#8211; 60</li>
<li>Agile &#8211; 20</li>
<li>UML &#8211; 61</li>
<li>SOA &#8211; 8</li>
<li>WebServices &#8211; 4</li>
<li>SOAP &#8211; 13</li>
<li>BPEL &#8211; 3</li>
<li>EJB &#8211; 45</li>
<li>JMS &#8211; 26</li>
<li>JMX &#8211; 0</li>
<li>Tibco &#8211; 13</li>
<li>AJAX &#8211; 4</li>
<li>PHP &#8211; 5</li>
<li>Eclipse &#8211; 51</li>
<li>HTML &#8211; 71</li>
<li>JSP &#8211; 86</li>
<li>XML &#8211; 145</li>
<li>XSL &#8211; 26</li>
<li>XSLT &#8211; 22</li>
</ul>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aujava.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aujava.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aujava.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aujava.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aujava.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aujava.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aujava.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aujava.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aujava.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aujava.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aujava.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aujava.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aujava.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aujava.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aujava.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aujava.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=14&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aujava.wordpress.com/2006/08/13/java-technologies-popularity-in-sydney/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8dd7a2f17682913d8e7e8797b4647c6f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aujava</media:title>
		</media:content>

		<media:content url="http://aujava.files.wordpress.com/2006/08/aujava_logo.gif" medium="image">
			<media:title type="html">AuJava logo</media:title>
		</media:content>
	</item>
		<item>
		<title>Generic DAO and more</title>
		<link>http://aujava.wordpress.com/2006/08/09/generic-dao-and-more/</link>
		<comments>http://aujava.wordpress.com/2006/08/09/generic-dao-and-more/#comments</comments>
		<pubDate>Wed, 09 Aug 2006 23:58:34 +0000</pubDate>
		<dc:creator>Robert Sayfullin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">https://aujava.wordpress.com/2006/08/09/generic-dao-and-more/</guid>
		<description><![CDATA[Since Java 5 introduced new generics feature many aspects of our Java coding has changed. DRY approach to many tiers in J2EE soared and become common place. Even such a conservative monsters as IBM come up with nice generic-based patterns. Have a look at this really good article Dont repeat the DAO. They did not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=13&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Since Java 5 introduced new generics feature many aspects of our Java coding has changed. DRY approach to many tiers in J2EE soared and become common place. Even such a conservative monsters as IBM come up with nice generic-based patterns. Have a look at this really good article <a href="http://www-128.ibm.com/developerworks/java/library/j-genericdao.html" title="Dont repeat the DAO">Dont repeat the DAO</a>. They did not invent something new but rather summarised bit and pieces in pretty well done generic DAO. However if you have simple web-based CRUD project you can go even further and generify your managers. Most of the time managers do exactly the same job providing additional wrapper around DAO. So it is the same CRUD as we had in DAO but DataBase -agnostic. So lets have a look at our DAO:<br />
<span id="more-13"></span></p>
<pre>package com.maersk.hrb.dao;

import java.io.Serializable;
import java.util.List;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class GenericDao  extends HibernateDaoSupport {
    private Class modelClass;
    private SessionFactory sessionFactory;

public GenericDao(Class modelClass) {
        this.modelClass = modelClass;
    }

public PK create(T o) {
        return (PK) getHibernateTemplate().save(o);
    }

public T read(PK id) {
        return (T) getHibernateTemplate().get(modelClass, id);
    }

public void update(T o) {
    	getHibernateTemplate().update(o);
    }

public void delete(T o) {
    	getHibernateTemplate().delete(o);
    }

public List getObjects(DetachedCriteria criteria) {
		return getHibernateTemplate().findByCriteria(criteria);
	}

public List getObjects(Serializable[] ids) {
		return getHibernateTemplate().find("from "+modelClass.getSimpleName()+" alias where alias.id in ?", ids);
	}

public List getObjects() {
		return getHibernateTemplate().find("from "+modelClass.getSimpleName());
	}
}</pre>
<p>Nothing new here. Well known generic DAO. I do not have any finder method here because my application is really simple. Anyway finders would bring big difference to idea.<br />
So this is our generic manager:</p>
<pre>package com.maersk.hrb.domain.logic;

import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.NotImplementedException;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;

import com.maersk.hrb.dao.GenericDao;
import com.maersk.hrb.domain.BaseObject;

public class GenericManager {
    private Class modelClass;
    private Class
pkClass;
	private GenericDao dao;

private static Map managersMap = new HashMap();

public GenericManager(Class modelClass, Class
pkClass) {
        this.modelClass = modelClass;
        this.pkClass = pkClass;
        this.dao = new GenericDao(modelClass);
        managersMap.put(modelClass, this);
    }

public static GenericManager lookupManagerByClass(Class modelClass){
    	return (GenericManager) managersMap.get(modelClass);
    }

public static GenericManager lookupManagerByClassName(String modelClassName){
    	Class modelClass;
		try {
			modelClass = Class.forName(modelClassName);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException(e.getMessage(), e);
		}
    	return (GenericManager) managersMap.get(modelClass);
    }

public  static GenericManager lookupManagerBySimpleClassName(String modelClassName){
    	return lookupManagerByClassName("com.maersk.hrb.domain."+modelClassName);
    }

public void setSessionFactory(SessionFactory sessionFactory) {
		if (dao != null)
			dao.setSessionFactory(sessionFactory);
	}

public GenericManager(Class modelClass) {
    	this(modelClass, (Class
) Long.class);
    }

public Class getModelClass() {
		return modelClass;
	}

public void setDao(GenericDao dao) {
        this.dao = dao;
    }

public T getObject(String id) {
        try {
			Constructor
constructor = pkClass.getConstructor(String.class);
			PK newInstance = (PK)constructor.newInstance(id);
			return dao.read(newInstance);
		} catch (Exception e) {
			throw new RuntimeException("Wrong PK class");
		}
    }

public List getObjects(DetachedCriteria criteria) {
    	return dao.getObjects(criteria);
    }

public List getObjects(String[] ids) {
        return dao.getObjects(ids);
    }

public List getObjects(Serializable[] ids) {
        return dao.getObjects(ids);
    }

public T getObject(Long id) {
        return dao.read((PK)id);
    }

public List getObjects() {
        return dao.getObjects();
    }

public void removeObject(String id) {
        T object = getObject(id);
        dao.delete(object);
    }

public boolean isFieldValueUnique(String fieldName,Object fieldValue, T currentObject) {
    	throw new NotImplementedException("Not yet, sorry");
    }

public void saveObject(T object) {
    	if(object.isNew())
    		dao.create(object);
    	else
    		dao.update(object);
    }
}</pre>
<p>Each manager creates his own DAO and registers itself in map. Note three lookup methods allowing us to get managers for specific model class. It is the sample of &#8216;Conventioin over Configuration&#8217; principle. What the point of assigning managers to facade if we can explicitly get them when and where we need it? What is the point of defining Spring beans for DAO if the only place we use them is managers? The coupling here is not tough and I have no problem with that. Afterall coupling is evel thing when you try plug different implementations of modules, refactor, or anyhow else intoduce significant changes.<br />
Despite of some coupling here we obviously not gonna have such problems. The only thing that I do not like here is sessionFactory. Managers only need sessionFactory to pass to their DAOs. In next post I&#8217;ll address such issues. Now lets continue to our spring beans definitions:</p>
<pre>&lt;bean id="managerTemplate"  abstract="true"&gt;
	&lt;property name="sessionFactory"&gt;
		&lt;ref bean="sessionFactory"/&gt;
	&lt;/property&gt;
&lt;/bean&gt;&lt;bean id="staffMemberManager" class="com.maersk.hrb.domain.logic.GenericManager"  parent="managerTemplate"&gt;
	&lt;constructor-arg&gt;
		&lt;value&gt;com.maersk.hrb.domain.StaffMember&lt;/value&gt;
	&lt;/constructor-arg&gt;
&lt;/bean&gt;

&lt;bean id="aidQualificationManager" class="com.maersk.hrb.domain.logic.GenericManager" parent="managerTemplate"&gt;
	&lt;constructor-arg&gt;
		&lt;value&gt;com.maersk.hrb.domain.AidQualification&lt;/value&gt;
	&lt;/constructor-arg&gt;
&lt;/bean&gt;

&lt;bean id="remunerationEventManager" class="com.maersk.hrb.domain.logic.GenericManager" parent="managerTemplate"&gt;
	&lt;constructor-arg&gt;
		&lt;value&gt;com.maersk.hrb.domain.RemunerationEvent&lt;/value&gt;
	&lt;/constructor-arg&gt;
&lt;/bean&gt;

&lt;bean id="staffPositionHeldManager" class="com.maersk.hrb.domain.logic.GenericManager" parent="managerTemplate"&gt;
	&lt;constructor-arg&gt;
		&lt;value&gt;com.maersk.hrb.domain.StaffPositionHeld&lt;/value&gt;
	&lt;/constructor-arg&gt;
&lt;/bean&gt;</pre>
<p>Simple, short. No more scroll-blindness when looking at applicationContext.xml! This is what I wanted.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aujava.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aujava.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aujava.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aujava.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aujava.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aujava.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aujava.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aujava.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aujava.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aujava.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aujava.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aujava.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aujava.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aujava.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aujava.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aujava.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aujava.wordpress.com&amp;blog=303857&amp;post=13&amp;subd=aujava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aujava.wordpress.com/2006/08/09/generic-dao-and-more/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8dd7a2f17682913d8e7e8797b4647c6f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aujava</media:title>
		</media:content>
	</item>
	</channel>
</rss>
