Wednesday, December 29, 2010

Hibernate - Reading a datasource from a jndi

I was writing this utility that read the data produced by the main application, but presented it in a different way - basically sliced and diced the information such that it was more meaningful to the user.
My goal for this utility was simple - provide as little configurations as possible - make it work more like a plug-and-play utility.
To achieve this, the first goal was to read the same jndi’s the main application was reading to fetch data. I didnt want the user to have to re-enter the connection params. Fairly simple request right?
Here’s what i had to do to achieve this:
Step1 - The JNDI was already defined - in the tomcat server.xml in this case. So make a note of the jndi name
   
      
 auth=”Container”
        type=”javax.sql.DataSource”
….
Step2 - Update your Spring application context to include the datasource bean as follows,
 
          class=”org.springframework.jndi.JndiObjectFactoryBean”>
      /jdbc/unity”/>  
     
   

Step2 - Last step - update your Context.xml (if you dont have one, create one under META-INF)
  
         jdbc/unity”
                       type=”javax.sql.DataSource”
                       global=”jdbc/unity”/>
  


Thats it!

Tuesday, December 28, 2010

Formatting Struts 2 s:checkboxlist tag

I recently had the need to format the struts 2 tag. By default it appears as a horizontal formatted list (checkBox1[] checkBox2[] checkBox3[] etc) but since the number of checkboxes were large, i wanted them to appear in a tabular format.

Here's what i did:
- After doing a quick Google search i figured that i needed to overwrite the default Freemarker template.
- All the templates are located in the struts-core.jar

1. Create a new directory structure at the root of my application called template/myapp and template/myapp_simple
2. The template we're looking for is checkboxlist.ftl. This is located in the struts-core.jar under templates/xhtml folder. We want to override that, so lets create our own version of it. To start with lets copy the existing freemarker templates (located in struts-core.jar templates/xhtml) into your new template/myapp folder.
3. Now edit the filer checkboxlist.ftl. As you can see its referring to the template stored under the simple folder.
<#include "/${parameters.templateDir}/simple/checkboxlist.ftl" />
Lets change that so that it points to your directory structure
<#include "/${parameters.templateDir}/myapp_simple/checkboxlist.ftl" />
4. Now lets copy the checkboxlist.ftl located in the template/simple folder (from the struts-core.jar) into your template/myapp_simple folder.
5. Lets override this file now. What i want to do is make all the checkboxes appear in a 4 column table. So here's what my checkboxlist.ftl looks like.


<#assign itemCount = 0/>
<#if parameters.list?exists>
<@s.iterator value="parameters.list">
<#assign itemCount = itemCount + 1/>
<#if parameters.listKey?exists>
<#assign itemKey = stack.findValue(parameters.listKey)/>
<#else>
<#assign itemKey = stack.findValue('top')/>

<#if parameters.listValue?exists>
<#assign itemValue = stack.findString(parameters.listValue)/>
<#else>
<#assign itemValue = stack.findString('top')/>

<#assign itemKeyStr=itemKey.toString() />
<#if itemCount%4=0>

<#elseif itemCount%4=2>

<#elseif itemCount%4=3>

<#else>


<#rt/>
<#if tag.contains(parameters.nameValue, itemKey)>
checked="checked"<#rt/>

<#if parameters.disabled?default(false)>
disabled="disabled"<#rt/>

<#if parameters.title?exists>
title="${parameters.title?html}"<#rt/>

<#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
<#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
/>

<#if itemCount%4=0>

<#else>



<#rt/>

<#else>


Thats it

Monday, July 12, 2010

I love my Grill!

Its the 4th of July weekend and so i thought its about time i got myself a Grill.

My budget was limited, and so even tho the webers looked very appealing i had to stick within my $200 limit (self imposed ofcourse).

I ended up going for the Nexgrill (http://www.homedepot.com/h_d1/N-5yc1vZ1xg1Zbwo59/R-202326969/h_d2/ProductDisplay?langId=-1&storeId=10051&catalogId=10053)
My first BBQ turned out to be pretty good. Here are few recipes that went down well with the peeps.

1. Pork Chops (http://www.foodnetwork.com/recipes/paulas-home-cooking/grilled-pork-chops-recipe/index.html)
2. Chicken Tikka Masala (http://allrecipes.com//Recipe/chicken-tikka-masala/Detail.aspx)
3. Grilled Shrimp (http://www.foodnetwork.com/recipes/ina-garten/grilled-herb-shrimp-recipe/index.html)

Installing GWT on Ubuntu 10.04

When trying to run GWT in hosted mode i got the following,

** Unable to find a usable Mozilla install **
You may specify one in mozilla-hosted-browser.conf, see comments in the file for details.

To overcome this i downloaded mozilla-1.7.13 from the following location,
http://google-web-toolkit.googlecode.com/svn/tools/redist/mozilla/mozilla-1.7.13.tar.gz

I then updated the mozilla-hosted-browser.conf to point to my newly unziped mozilla dist.

When i retried to launch the GWT hosted browser i now got the following,

** Unable to load Mozilla for hosted mode **
java.lang.UnsatisfiedLinkError: /
/mozilla-1.7.13/libxpcom.so: libstdc++.so.5:
cannot open shared object file: No such file or directory

source: http://whatwouldnickdo.com/wordpress/99/unable-to-load-mozilla-for-hosted-mode-gwt-ubuntu-810-linux/

The key to troubleshooting the problem is in the second line, libstdc++.so.5 to be exact. It can’t find this C++ library. Turns out the hosted browser needs libstdc++5, but the version currently installed on my 8.10 system is libstdc++6. So you can either:

I had trouble installing the libstdc++5 using sudo apt-get install libstdc++5


So instead i did the following,
# wget http://ftp.egr.msu.edu/debian/pool/main/g/gcc-3.3/libstdc%2b%2b5_3.3.6-20_i386.deb
# dpkg-deb -x libstdc++5_3.3.6-20_i386.deb libstdc++5
# cp -p libstdc++5/usr/lib/libstdc++.so.5.0.7 /usr/lib
# cp -p libstdc++5/usr/lib/libstdc++.so.5 /usr/lib

This solved the problem!

Saturday, June 12, 2010

Remotely accessing my Ubuntu server via Windows

- Install cygwin with x11 packages (see cygwin X)
- start cygwin
- /usr/bin/startxwin.exe

In the Xwindows window type in,
- ssh -Y rpaiva@

- you can launch xterm&
- you can launch eclipse&

Wavin Flag - K'naan

Search This Blog