Thursday, March 28, 2013

Insufficient Access Exception when adding new column to SQL statement

I had a strange thing happen today.   I needed to add a new column to an existing java agent that uses JDBC to pull from Oracle.  

I had two agents that do the same thing except pull from different tables.   Yesterday I added the new column to the first agent and everything ran fine.   Today I was fixing the second agent, and after adding the new column, I got  an "Insufficient Access Exception" from Oracle.   I added it the exact same way as I did to the first agent. 

After trying all sorts of things and talking with the DBA, he moved the column to a different place with the statement and it worked.   Crazy!!   Before changing it, the statement worked when you copied it and ran in an TOra Oracle client.   For some reason, changing the order fixed the issues and the column read fine and caused no exceptions.  

When I first added the column, I added to the end.  Moving towards the beginning of the statement fixed the issue.   Note:  there was no comma after the last column, and there was a space before the FROM.  The syntax was correct.

Lesson:   In JDBC, changing column order can sometimes fix strange exceptions.   Why:  who knows.

Wednesday, March 27, 2013

Creating simple xpages reports using data tables

What I am going to show in this post is how I created simple reports that the user can control.   I decided to use a data table to display the report data.

Before you start it looks like this.

The user then chooses the date selection, and the report auto populates.

Here is how I coded it:

For each report I created a separate custom control instead of adding directly to the xpage as I have done in the past.   At first I avoided custom controls, because I learned that they were like subforms, and I have found subforms to be more trouble than they are worth in the past.   Lately I have been working my way through Matt White's xpages101 series, and he does everything in custom controls.   I am starting to come around.

In the report custom control, I created a section, and in the section the combo box and the data table.   The data table is in a Div so that is partially refreshed using the onChange event of the combo box.

The onChange event simply sets a sessionScope variable for the user selection:

var approvedDate = getComponent("comboBoxCC1").getValue();
sessionScope.report1 = approvedDate;

The custom control is bound to a view that contains all documents categorized a single string.
var date = sessionScope.report1
var returnValue = document1.getItemValueString("Store") + "~" + document1.getItemValueString("Dept") + "~" + date
return returnValue

In the data table the computed fields are bound to specific columns of the view.

The only other piece of code is in the afterPageLoad event of the custom control, I added a line of code to clear the sessionScope variable.   This prevents the page remembering what was previously selected.  I experimented using a viewScope variable instead, but couldn't get it to work.
sessionScope.report1 = ""

I do realize that nothing here is particularly ground breaking, but I still wanted to document what I did for at least my own future reference. 

4/10 UPDATE:
I needed to make another copy of this report, and changed it so that combo box was bound directly to a ViewScope variable.   By doing this there is no need to set the variable to "".

Tuesday, March 12, 2013

Making the browser behave when saving new documents

One issue I had encountered early on in my current project was that the document would create a duplicate copy when the user pushed F9 to refresh the page.   This happened whether I used a partial refresh or a full refresh.   I spent a lot of time trying different things until I found a very helpful blog post by Tommy Valand:

Basically this redirects back to the current document, causing the refresh to do nothing but refresh the current document.   I have found this very useful.  I am going to include this function whenever I do a in SSJS.

To implement, but the code below in an SSJS code library.   Then call it like this:  redirectToCurrentDocument( false, "Invoices" )

I had to make two changes to Tommy's code to get it to work how I needed it.   

  • First I had to use .getNoteID() instead of .getUniversalID().  I was getting run time errors and this seemed to fix them, why I don't know.
  • Second, I added code to take the user back to the tab they were working on.  Without the tab parameter and query string it would always take the user back to the first tab.  

Here is the code:  (Again, credit for this belongs to Tommy Valand)

function redirectToCurrentDocument( switchMode:boolean, tab){
 try {
   if( typeof currentDocument === 'undefined' || viewScope.stopRedirect ){ return; }
   // Gets the name of the XPage. E.g. /Person.xsp
   var page = view.getPageName();
   // Finds extra parameters, strips away XPages parameters/trims leading &
   var parameters = context.getUrl().getQueryString().substring(1);
   var extraParameters = parameters.replace( 
    /([&\?^]*_[a-z0-9=]+[&]{0,1})|(tab=\w{0,}[\&]{0,1})|(action=\w{4}Document[\&]{0,1})|(documentId=[\w]{32}[\&]{0,1})/ig, '').replace( /\&$/, '' );
   // Gets the unid of the current document
    var unid = document1.getDocument().getNoteID();  //changed to use NoteID since it gave runtime errors
   // Sets/changes the action according according to the mode the document is in
   var isEditable = currentDocument.isEditable();
   if( switchMode ){ isEditable = !isEditable; } // false -> true / true -> false
   var action = ( isEditable ) ? 'editDocument' : 'openDocument';
   // Open the current document via a get request
   var redirectUrl = page + '?documentId=' + unid + '&action=' + action;
   if( extraParameters ){ redirectUrl += '&' + extraParameters; }
    redirectUrl += '&tab=' + tab
   context.redirectToPage( redirectUrl );
 } catch(e){ /* Exception logging */ }

Tuesday, March 5, 2013

Teaching my daughter Java

We homeschool our four children.  We have many reasons for doing so, and one is to teach to our children's strengths.   My oldest daughter is very interested in computers and seems to understand concepts quickly.

It occurred to me a few months ago that she is now old enough to start learning some marketable skills.   She just turned 12, but I think she is ready to be stretched and learn about what Dad does for a living.  Do I expect her to be a programmer, well maybe if she decides she likes it, but I think the skills I am teaching her translate very well into other areas.

The first thing I did before starting was to show her some salaries on for Java programmers.   This helped her realize that she should take this seriously.    I also showed her a search of Lotus Notes Domino programmers and how many fewer jobs there were out there.    I did this to help her understand why her Dad is also spending so much time learning new things.

A side benefit, is that it helps me contribute to of her education, something my wife has done entirely up to this point.   It also gives me a chance to spend time with her as she is going through the awkward stage of growing into a young woman.

To teach her Java, I am using a combination of resources.   I am mixing up book, audio, and video resources.   The majority of this is provided by the site:  My daughter seems to like the author Trevor Page.   He is younger and has a comfortable speaking style.

These are all the resources we are using:

  • Book:   This is a Trevor's book of the same name as his site:  How to Program With Java.   We bought the kindle version on Amazon.     
  • Book:   Murach's Java - This was my old textbook when I studied Java at a college in Dallas.   I really like this book, and I am having my daughter read selected pages on subjects we are covering.  
  • Book:   Head First Java  This the book I am reading to stay current. Later, I will use the many exercises in it to teach my daughter.  It is geared for readers with prior experience.

  • Audio:  Trevor has free podcasts on iTunes that match well with chapters from his book.

  • Video:  Trevor has a video teaching series on his website that we intend to subscribe to.   Right now, we are still watching the free videos he has included.
  • Video: - As we get further into Java, I intend to supplement using videos from's Java  courses.