Wednesday, August 19, 2009


Recently, I installed the LightUML plug-in for Eclipse. The installation "process" was easy and straightforward but when I tried to create class diagrams I encountered error dialogs from Eclipse. So, after a little web research, it basically required a couple of "configuration" particulars. Some of my notes are below, but basically I decided to tell LightUML to use the UMLGraph.jar from version 4.8 (instead of the 5.2 that I had installed). As far as I know (when I wrote this), doing so did not "mess up" my UMLGraph 5.2 installation; the configuration change(s) are isolated to the LightUML plug-in.

Here are my notes:
My LightUML Install Notes : This worked for me

Eclipse v3.4.1
GraphViz v
UMLGraph v4.8/v5.2 (see notes below)

=====Eclipse Plugin Settings==============
Preferences > Java > LightUML
* Graph file name: graph
* Output directory (...optional): src/main/lightuml
* Use package or project name as the graph file name: true
* Recurse into subpackages: true
* Javadoc executable path (optional): C:\Program Files\Java\jdk1.5.0_16\bin\javadoc.exe

Preferences > Java > LightUML > Class Diagrams > General
* attributes
* constructors
* operations
* UMLGraph extra command line parameters (optional): -outputencoding UTF-8

Preferences > Java > LightUML > Dot and Pic2plot
* Extra lookup path (optional): C:\develop\tools\graphviz\v2.24\bin
* Graphics format: png

Preferences > Java > LightUML > UML Graph
* UmlGraph.jar path: C:\develop\tools\umlgraph\UMLGraph-4.8\lib\UmlGraph.jar
* sequence.pic path: (empty) [but probably needs to be something if I try to use sequence diagrams]
* UMLGraph version 4.4+

=====Eclipse Plugin modifications============ (path...)/workspace/.metadata/.plugins/org.lightuml.core/ Change 1 : < file: build.xml > Description: For some reason, the ant script thinks that graphviz is failing even though it is just spitting out warnings about fonts. I commented out the <fail> tag in the Ant script and it allowed it to proceed. That is probably a workaround for telling Ant how to properly recognize/ignore the warnings.
<target name="dot-to-graphics">
<!-- load setting for this run (the dot-file-name) -->
<property file="runsettings.ini" />

<property environment="env"/>

<env key="PATH" path="${extra-lookup-path}:${env.PATH}"/>
<arg line="${dot-extra-param}"/>
<arg value="-T${graphics-format}"/>
<arg value="-ograph/${dot-file-name}.${graphics-format}"/>
<arg value="graph/${dot-file-name}.dot"/>
<!-- remove the dot file -->
<delete file="graph/${dot-file-name}.dot" />

<!-- =================================
<fail message="Error executing Graphviz 'dot' ::: ${dot.error}">
<length string="${dot.error}" when="greater" length="0"/>
================================= -->

Change 2: Description: As found on a sourceforge bug report, make all occurrances of 'useexternalfile' look like the following snippet; *At this time, I honestly do not know what this does.

Monday, July 13, 2009

Where are my iBatis log messages?

I had setup my webapps and Tomcat to use log4j according to their very own documentation [insert-link-here] but my webapps were not logging iBatis log messages nor the java.sql messages that it uses.

Short story first:
Because of what must obviously be classloader issues(as discussed ad nauseum on the web), I moved the following files from ...tomcat/common/lib to .../tomcat/server/lib:
  • commons-logging-1.1.1.jar
  • log4j-1.2.8.jar
Now, everything seems to work fine yet I only found ONE(1) web site which gave this advice (and it was not directly related to missing log entries). Hope it helps someone else since I spent quite a bit of time perusing the web.

Any feedback is welcome (of a constructive sort), but here are the key points I will take away from this lesson:
  • I think I would recommend this for any web application setup that uses JCL (either directly or through a dependent JAR).
  • Tomcat logging is working correctly via a file in .../tomcat/server/classes, and all webapps seem to be logging correctly as configured in their web-inf/classes/log4j.xml file

Tuesday, June 2, 2009

Prevent browser cache of JSP pages using Struts

I am sure this is addressed in a million places on the net but this is my blog, so there. Simply set the 'nocache' property to 'true' on the 'controller' in struts-config.xml (I am using Struts 1/classic).

[todo: add the example XML and the example HTTP Response before/after]

Wednesday, May 27, 2009

JFreeChart and Time-based Bar Charts

Ok... I do not get many comments on my posts (because they are short and boring) but am really looking for people to comment on this one because I am looking for feedback.

I have used CeWolf/JFreeChart for about two years now (off and on). If someone asked me to rank my knowledge of them (1 to 10) I would answer 5 - not an expert, not a novice. Recently, it has become common for my users to want time-based charts. It seems that JFreeChart does not provide much utility for building bar charts based on time series. Am I seeing this correctly? or am I failing to understand a fundamental concept of JFreeChart? (or... other?)

Any feedback?

Tuesday, May 5, 2009

Modify Windows Services Configuration

This is mainly for my reference, but I wanted to modify the description associated with some Services in my installation of Windows. I found the following website the most helpful... I am sure there are more:

I used the following two lines to do what I wanted:
sc query state= all | findstr "DISPLAY_NAME STATE" >svc.txt
sc description {service_name} "description_goes_here"

Force Displaytag Export to Text

When I was using displaytag to export to excel, one of my columns contained text which was being recognized as numeric (scientific notation). When googling for a possible solution, seems like a LOT of people have had this problem in various ways (displaytag or otherwise). Thanks to this webpage, my solution was to write the following column decorator:

Custom Decorator

request.setAttribute("yourdecorator", new DisplaytagColumnDecorator() {
public Object decorate(Object o, PageContext pageContext, MediaTypeEnum media) {
String decorated = (String)o;
if (media.equals(MediaTypeEnum.EXCEL) || media.equals(MediaTypeEnum.CSV)) {
decorated= "=\"" + packet + "\"";

return decorated

<display:column title="your-title" media="xml excel csv" property="your-property" decorator="yourdecorator" />

I have not run into any issues with this approach yet. If you do, I would appreciate a comment back. Thanks again to the guy who posted the hint that I reference previously.

p.s. Someone also suggested that I prepend the text with a unicode non-breaking space (see code following). Visually, it has the desired effect but it also modifies the text in the field so I do not like the solution as well. I just offer that solution to those who might want to use it.

Custom Decorator

decorated= "\u00a0" + packet;

Tuesday, April 14, 2009

Crystal Reports IllegalStateException

So, my companies web app was throwing this nebulous IllegalStateException exception (see stacktrace below) that did not seem to adversely affect the application but I just couldn't let it go. I was able to resolve it like this:
  1. First, I googled it... not much help in the first few pages other than telling me what I already knew. 'out' was being called after it had been commited/closed.
  2. Though I usually don't have to do this anymore, it finally dawned on me to look at the compiled JSP code. (This was legacy, pure JSP... no struts nor nothing.) We were using Tomcat 5.5 and Eclipse 3.3+ so my JSP class was in the 'work' directory of my Eclipse project. Sure enough, there were out.print("") in my compiled JSP class. Where were they coming from?
  3. We had no explicit out.print() in our JSP code, so just looking at where they were in the class and how our JSPs were constructed, it seemed a close correspondence to an out reference for every JSP directive (like @page, etc.)
  4. So, I googled this: illegalstateexception crystal tomcat
    and came across this link which basically tells you to avoid line breaks between your JSP directives.
  5. Problem solved.

|ESD|13:28:22,363|ERROR|Servlet.service() for servlet jsp threw exception [http-12080-Processor22|org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/esd].[jsp]]
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(
at org.apache.catalina.connector.ResponseFacade.getWriter(
at org.apache.jasper.runtime.JspWriterImpl.initOut(
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(
at org.apache.jasper.runtime.PageContextImpl.release(
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(
at org.apache.jsp.pages.reports.CrystalReportViewer_jsp._jspService(
at org.apache.jasper.runtime.HttpJspBase.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.jasper.servlet.JspServletWrapper.service(
at org.apache.jasper.servlet.JspServlet.serviceJspFile(
at org.apache.jasper.servlet.JspServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.displaytag.filter.ResponseOverrideFilter.doFilter(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.valves.ErrorReportValve.invoke(
at org.apache.catalina.core.StandardEngineValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.apache.coyote.http11.Http11Processor.process(
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(
at org.apache.tomcat.util.threads.ThreadPool$

Wednesday, April 8, 2009

Script your ODBC Data Sources (MySQL)

Ok... admittedly this has to do with Windows scripting and not Java nor Javascript but is something that affects many of my projects. If your computer needs ODBC Data Sources, you can script their creation (particularly useful for configuring new developers' computers).

This script should provide a fairly useful start to customizing your own version. I am going to assume that it is fairly self-explanatory but you can always post a response if you do not agree or have a question.

' This script creates one or more ODBC Data Sources.

' Usage: >cscript crystal.odbc.test.vbs
' Notes:
' * Search for 'configure-here' for all customization options
Const HKEY_LOCAL_MACHINE = &H80000002

strPrefix = "winmgmts:{impersonationLevel=impersonate}!\\"
strComputer = "."
strSuffix = "\root\default:StdRegProv"
strObjRef = strPrefix & strComputer & strSuffix ': wscript.echo strObjRef
Set objReg = GetObject(strObjRef) 'The Set keyword is mandatory

DriverNames = Array("SQL Server", "MySQL ODBC 3.51 Driver") 'Generally, do not modify these
Drivers = Array("C:\WINDOWS\System32\SQLSRV32.dll", "C:\WINDOWS\system32\myodbc3.dll") 'Generally, do not modify these
' Configuration Section
Const Chosen = 1 'configure-here: Zero-based index into the following two arrays; i.e. which DB are you using
Const Server = "xxxwebtest" 'configure-here: the machine where the DB is hosted
Const Port = "3307" 'configure-here: the port where the DB is hosted
Const Uid = "root" 'configure-here: the username to the DB
Const Pwd = "admin" 'configure-here: the password to the DB
ConnectionList = Array("dbone", "dbtwo", "etcetera") 'configure-here: see Note 1 below

REM *** Note 1 *** This is the array of ODBC Names which you will be creating;
REM also is the name of the database which the odbc connects to
'=== End : Configuration Section ================================

for each connection in ConnectionList
wscript.echo "*** Start *** Creating ODBC Data Source: " & connection

' *** Step 1 *** Create new Data Source Entry in system folder ...\ODBC Data Sources
strKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
strValueName = connection
strValue = DriverNames(Chosen)
call WriteToRegistry

' *** Step 2 *** Create Data Source configuration in new user-defined folder {connection}
strKeyPath = "SOFTWARE\ODBC\ODBC.INI\" & connection
objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath

' *** Step 2a *** Database
strValueName = "DATABASE"
strValue = connection
call WriteToRegistry

' *** Step 2b *** Driver
strValueName = "DRIVER"
strValue = Drivers(Chosen)
call WriteToRegistry

' *** Step 2c *** Server
strValueName = "SERVER"
strValue = Server
call WriteToRegistry

' *** Step 2d *** Port
strValueName = "PORT"
strValue = Port
call WriteToRegistry

' *** Step 2e *** UID
strValueName = "UID"
strValue = Uid
call WriteToRegistry

' *** Step 2f *** PWD
strValueName = "PWD"
strValue = Pwd
call WriteToRegistry

' *** Step 2g *** Trusted_Connection : SQL Server only?
strValueName = "Trusted_Connection"
strValue = "Yes"
' call WriteToRegistry

' *** Step 2h *** Description
strValueName = "DESCRIPTION"
strValue = "EditMeThroughRegEdit"
call WriteToRegistry

wscript.echo "*** Finished *** Creating ODBC Data Source.\n"
next 'connection
'===== End of Script =====

' Subroutines and Functions
Sub WriteToRegistry
Const debugDesired = false
If debugDesired Then
wscript.echo "Simulating name/value to: HKEY_LOCAL_MACHINE\" & strKeyPath & ": " & strValueName & "/" & strValue
wscript.echo "Modifying name/value to: HKEY_LOCAL_MACHINE\" & strKeyPath & ": " & strValueName & "/" & strValue
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
End If
End Sub

Tuesday, March 24, 2009

iBATIS Parameter Maps (a.k.a my iBATIS brain f*rt)

On a project using iBATIS, I was receiving the following stacktrace:

org.springframework.dao.TransientDataAccessResourceException: SqlMapClient operation; SQL [];  
--- The error occurred in {myproject}/PlanningProject.xml. 
--- The error occurred while applying a parameter map. 
--- Check the {myparametermap}  
--- Check the parameter mapping for the 'startDate' property.  

--- Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in com/kpe/resourcePlanning/domain/dao/ibatis/PlanningProject.xml. 
--- The error occurred while applying a parameter map. 
--- Check the {myparametermap}  
--- Check the parameter mapping for the 'startDate' property.  
--- Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).

And this is the snippet of the parameter map that is significant:

  <parameterMap id="updatePmap" class="PlanningProject">
    <parameter property="startDate" jdbcType="TIMESTAMP" javaType="org.joda.time.LocalDate" typeHandler="com.kpe.resourcePlanning.domain.dao.ibatis.TypeHandlerCallbackLocalDate" />
    <parameter property="endDateConstraint" jdbcType="TIMESTAMP" javaType="org.joda.time.LocalDate" typeHandler="com.kpe.resourcePlanning.domain.dao.ibatis.TypeHandlerCallbackLocalDate" />     
    <parameter property="modifiedBy" jdbcType="VARCHAR" />
    <parameter property="id" jdbcType="NUMBER" />

  <update id="update" parameterMap="updatePmap">
    UPDATE resourcePlanning.planningproject
        startDate = #startDate#,
        endDateConstraint = #endDateConstraint#,
        modifiedBy = #modifiedBy#,
        modifiedDate = now() 
        projectId = #id#

Well, my project hardly ever used explicit parameter maps. Usually, statements used the parameterClass="" syntax. So, as you might already know, my syntax was terribly wrong. The correct syntax follows. The thing to note (at least for me) is that the order of the individual SET parameters must match the order given in the parameter map that you use.

  <parameterMap id="updatePmap" class="PlanningProject">
    <parameter property="startDate" jdbcType="TIMESTAMP" javaType="org.joda.time.LocalDate" typeHandler="com.kpe.resourcePlanning.domain.dao.ibatis.TypeHandlerCallbackLocalDate" />
    <parameter property="endDateConstraint" jdbcType="TIMESTAMP" javaType="org.joda.time.LocalDate" typeHandler="com.kpe.resourcePlanning.domain.dao.ibatis.TypeHandlerCallbackLocalDate" />     
    <parameter property="modifiedBy" jdbcType="VARCHAR" />
    <parameter property="id" jdbcType="NUMBER" />

  <update id="update" parameterMap="updatePmap">
    UPDATE resourcePlanning.planningproject
        startDate = ?,
        endDateConstraint = ?,
        modifiedBy = ?,
        modifiedDate = now() 
        projectId = ?

Monday, March 23, 2009

Animate Your Page During Confirmation

I desired the following feature on my page. When the user clicked a link, do the following:
  1. Use scriptaculous animations to "get rid of" the current page (goal is to eliminate other links and form submit buttons and provide visual feedback that a 'process' has started).
  2. Display the dialog that was *already* coded into the link's onclick event.
  3. If they choose 'ok', give them visual feedback that the action has been submitted and then *continue* to the link destination.
  4. If they choose 'cancel', restore the page.

Solution: yourpage.jsp
Event.observe( window, 'load',
  function() {
      //alert('observing window load');


          function(value, index) {
              var old = value.onclick;

              value.onclick = function() {

                  new Effect.SlideUp('pagecontent', {
                      duration: 1.0,
                      queue: 'front'

                  new Effect.Fade('copyRight', {
                      duration: 1.0,
                      queue: 'end',
                      afterFinish: function(o) {
                          var rv =;

                          if (rv) {
                              // alert('you chose ok');

                              new Effect.Appear('waitNotification', {
                                  queue: 'end'

                              new Effect.Highlight('waitNotification', {
                                  queue: 'end'
                              new Effect.Appear('copyRight', {
                                  queue: 'end'

                              location.href = value;

                          } else {
                              //alert('you chose cancel');

                              new Effect.SlideDown('pagecontent', {
                                  duration: 1.0,
                                  queue: 'front'
                              return false; // this return doesn't have any effects currently


                  return false; // always return false



A slight improvement; do not begin the navigation until the last animation is finished:
snippet: yourpage.jsp
new Effect.Appear('copyRight', { 
    queue: 'end',
    afterFinish: function(o) {
     location.href = value;

//location.href = value;

Tuesday, March 17, 2009

iBATIS Datasource Configuration (plus Spring)

On a project, we originally used iBATIS "raw" and had the prototypical datasource defined like this:

    <transactionManager type="JDBC">     
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${ibatis.mysql.driver}"/>
<property name="JDBC.ConnectionURL" value="${ibatis.mysql.url}/resourcePlanning" /> jdbc:mysql://localhost:3306/powerSource" />
<property name="JDBC.Username" value="${ibatis.mysql.user}"/>
<property name="JDBC.Password" value="${ibatis.mysql.password}"/>

<property name="Pool.PingQuery" value="select 1"/>
<property name="Pool.PingEnabled" value="true"/>
<property name="Pool.PingConnectionsOlderThan" value="${ibatis.timeout}"/>


Upon improving our application architecture to use true DAOs, we concurrently upgraded to use Spring DI in our web app and subsequently took advantage of using Spring 'template' wrappers. However, changing the configuration was quite a lesson learned on my part:

Step 1: Remove transactionManager from iBATIS

Step 2: Create new 'datasource' bean using Spring
    <bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
<property name="url" value="${ibatis.mysql.url}/resourcePlanning"/>
<property name="username" value="${ibatis.mysql.user}"/>
<property name="password" value="${ibatis.mysql.password}"/>
<property name="driverClassName" value="${ibatis.mysql.driver}"/>

<property name="testWhileIdle" value="true"/>
<property name="validationQuery" value="select 1"/>

<property name="logAbandoned" value="true"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="3600"/>

<property name="maxWait" value="20"/>
<property name="maxIdle" value="10"/>
<property name="maxActive" value="-1"/>


Step 3: Create new Spring-wrapped SqlMapClient using new 'datasource' bean

    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">

<property name="transactionConfigClass">

<property name="dataSource">
<ref bean="dataSource"/>


Thursday, March 12, 2009

Struts Multibox

This is going to be a useless post if I do not remember to get back to this, but I created a rather elegant way of doing checkboxes in tables (displaytag none-the-less) so that Struts 1.x actions could easily get the objects to which they refer.

Stay tuned...

Thursday, January 22, 2009

"More" Dynamic Forms with Struts

The goal behind this pot-pourri of code snippets is that I had a
spreadsheet-like form whose purpose was to collect information that was
relative to the time/date when the form was being viewed (i.e. "dynamic").
Hopefully, someday I will get the time to cohesively explain the relationship
between the code snippets but they should prove of some value in the meantime.


On Sun, 1 Dec 2002, Martin Cooper wrote:

Date: Sun, 1 Dec 2002 22:18:05 -0800 (PST)
From: Martin Cooper Reply-To: Struts Developers List
Subject: Using a property of type Map in a DynaActionForm

As far as I can determine, it is not possible to create a DynaActionForm which
has a property of type Map. It is also not possible to extend it to be able
to accept a property of type Map. This seems like an unfortunate omission,
so I'd like to fix it.

First, though, I'd like to get some feedback on whether there is a reason
it's not currently supported, and on the best way of resolving it.

It's *supposed* to work if you declare the property type to be java.util.Map
instead of a concrete implementation of Map. You'll still need to create
your own Map instance at the moment -- I do mine in a custom reset() method,
but we probably also need a better solution based on an initial expression.


Custom Struts Action Form

package mypackage;

import java.util.HashMap;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

public class ActionFormRoles extends DynaActionForm {

public void reset(ActionMapping mapping, HttpServletRequest request) {
this.getMap().put("roleMap", new HashMap());
this.getMap().put("assignMap", new HashMap());

super.reset(mapping, request);

public void reset(ActionMapping mapping, ServletRequest request) {
super.reset(mapping, request);

Use of custom action form in struts-config.xml:

<form-bean name="roleForm" type="com.kpe.resourcePlanning.webapp.forms.ActionFormRoles">
<form-property type="java.util.Map" name="roleMap"/>
<form-property type="java.util.Map" name="assignMap"/>

JSP snippet showing use of map:
    <c:forEach var="headerPeriod" items="${rHeaderPeriods}" varStatus="column">
<td style="text-align: center;">
<c:set var="hash" value="${headerPeriod.year}.${headerPeriod.index}"/>

<c:if test="${column.index lt 2}">
<c:if test="${column.index gt 1}">
<html:text property="roleMap(${}.${headerPeriod.year}.${headerPeriod.index})" value="${role.timehash[hash].value}" size="3"/>


Struts Action which processes the form:

public ActionForward saveManageRoles(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
final ApplicationContext ac = this.getAppContext(request);
final ActionFormRoles f = (ActionFormRoles)form;

this.getApplicationController().saveRolesData(ac, (Map)f.get("roleMap"), (Map)f.get("assignMap"));
return mapping.findForward("manage");

Thanks to the following website for providing a converter for my html and xml text:

Monday, January 12, 2009

Prototype and Scriptaculous

These are snippets that I cannot yet remember by heart:

script type="text/javascript"

function() {
alert('put code here');
if ( $('notes') ){
// do stuff here