Tuesday, December 22, 2009

A Tamil Poem

I found this in one of my friend's Orkut profile. I wanted to proudly have it on my blog...

கனியிடை ஏறிய சுளையும் – முற்றல்
கழையிடை ஏறிய சாறும்
பனிமலர் ஏறிய தேனும் – காய்ச்சுப்
பாகிடை ஏறிய சுவையும்
நனிபசு பொழியும் பாலும் – தென்னை
நல்கிய குளிரிள நீரும்
இனிய என்பேன் எனினும் – தமிழை
என்னுயிர் என்பேன் கண்டீர்

Saturday, September 12, 2009

Hands on with SimpleFormController and DisplayTag

Recently, I got to work on SimpleFormController (Spring Framework class for handling web Form) with DisplayTag . It took me a while to get used to SimpleFormController. I should also mention that at first look it might seem lot of mess instead of trying to solve your problem, hey won't you get that feeling whenever you are trying to use any new technology??

I had to use debugger to understand the flow of control from various method. But you can follow this cheat sheet for complete flow diagram for SimpleFormController. You can inherit lot of methods based on your requirements, however following methods are the usual ones.

protected Object formBackingObject(HttpServletRequest request) throws ServletException;

public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception;

protected boolean isFormSubmission(HttpServletRequest request);

protected Map referenceData(HttpServletRequest request) throws Exception;

formBackingObject : will be called by createCommand method from SimpleFormController. On form request, if sessionForm is set to true the model object created by formBackingObject is put in session. On form submit, the object is taken from session and not created once again.

Sample code:
protected Object formBackingObject(HttpServletRequest request) throws ServletException {
SearchForm command = new SearchForm();
return command;

onSubmit: All form submit logic have to go into this. I would suggest you to go through javadoc for all onSubmit() variant.

public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
Object command, BindException errors) throws Exception {
SearchForm searchParam = (SearchForm) command;
System.out.println("your input is ... " + searchParam);

ModelAndView mv = null;
mv = showForm(request, errors, getSuccessView());
String pName = searchParam.getName();
if (pName == null || pName.length() == 0) {
pName = "Default_"; 
ProductSearch st = new ProductSearch();
st.setProducts(Util.getTableData(pName, 50));
HttpSession session = request.getSession();
session.setAttribute("TABLE_DATA", st.getAllProducts());
session.setAttribute("pageSize", searchParam.getPageSize());
System.out.println("done search ..... displaying results");
return mv;

Here, you can also include a check to see if the request is for DisplayTag pagination or actual form submission and you don't have to form submit logic for pagination requests.

isFormSubmission: Default implementation of this method returns true when request method is "POST". You can override this to change its behavior. You would have to do this when you want to use DisplayTag pagination. I have given the sample code below.

protected boolean isFormSubmission(HttpServletRequest request) {
return !request.getParameterMap().isEmpty();

referenceData: I didn't have to implement this method for my hands on.


DispalyTag provides lot of feature for high-level web presentation patterns like paging, cropping, sorting and exporting etc. The implementation with spring is pretty neat. All you have to do is add below dependency in your pom.xml


Or add displaytag-1.1.jar jar file into WEB-INF/lib. You are all set. For other configuration options, go through DisplayTag documentation.

I found this useful article on http://devx.com on Displaytag.

For my hands on , the JSP looks like the one below with DisplayTag code.

<form  name="product_search" action="formpage.html" method="POST">    
Name: <spring:bind path="command.name">
<input type="text" name="${status.expression}" 
id="name" value="${status.value}" />

Type: <spring:bind path="command.type">
<input type="text" name="${status.expression}" 
id="address" value="${status.value}" />

<input type="submit" value="Submit"/>
<input type="hidden" value="${pageSize}" name="pageSize" />


<c:set var="searchResultPageSizeOptions" value="10,25,50" />
<c:set var="selectedValue" value="10" />
<spring:bind path="command.pageSize">

<c:if test="${!empty pageSize}">
<c:set var="selectedValue" value="${pageSize}" />
<select name="<c:out value="${status.expression}"/>" id="pageval" onchange="javascript:changePageSize();">
<c:forTokens items="${searchResultPageSizeOptions}" delims=","
var="localPageSize" varStatus="status">
<option value="${localPageSize}" <c:if test="${selectedValue == localPageSize }">
</c:if> >${localPageSize}

<display:table name="sessionScope.TABLE_DATA" pagesize="${pageSize}" requestURI="formpage.html" class="results-table">
<display:column property="id" title="ID" sortable="true" />
<display:column property="name" title="Name" sortable="true" />
<display:column property="type" title="Type" sortable="true" />


I hope this would be helpful. Please post your comments.

Saturday, August 29, 2009

Outlook crashing with "Cannot start microsoft office outlook" msg

My outlook was crashing with "Cannot start Microsoft Office Outlook. Cannot open the Outlook window." error message. I had no clue what went wrong, but I knew why it was barfing on me. I was in a hurry to force shutdown my laptop yesterday. And I forgot to close Outlook (I closed every other running applications) before that.

The solution is ---

Start->run..then type the following -> "Outlook.exe /resetnavpane"

It worked like a charm!

Wednesday, August 19, 2009

Git is Awesome!

I got introduced to a distributed version control system called "Git". Git is not like traditional version control systems like SVN or CVS, but which provides much more features a developer can imagine/ would need for those painful code merges.

I had gone through this wonderful presentation by Bart Trojanowski and you can find them here. Bart provides brief intro on how Git works and how the version is tracked in Git ("the close to perfect" SCM). Then he goes on explaining about major features a developer would need to start using Git.

This presentation have been highly helpful for me to get grasp of Git. I want to thank Bart for this wonderful presentation and Ian Ward for making this screen-casts available online.

I installed Git on my PC machine using Cygwin. The stack is pretty awesome and neat. I would recommend the same for any PC users. When installing Git packages for cygwin, make sure you also pull in GUI tools ( gitk and git gui). If you are a tortoiseSVN or tortoiseCVS user, these tools would of great help.

Git uses local repository and does not need a remote (central) repository to get started. However, if you'd like to use some public Git repo servers for your hands-on, you could use either GitHub or repo.or.cz.

Follow the below link for setting up an account in Github. This is a screencast provided by learningrails website.

Version control with git.

As a summary, Git is a great version control system among other systems out there. Which comes with lots and lots of documentation, online tutorials and FREE public Git repositories. All of these could help developers a hassle-free transition towards using Git.