Java tips and tricks from a lady trying to play with the boys...

Thursday, March 15, 2012

ExtJS dateFormat Milliseconds

I am creating a page where I am using java.sql.Timestamp to keep track of when a record is updated. When displaying this on a grid, I was finding that the dateformat was failing when trying to display this data in a grid. I was passing the values to the page using JSON, and the date looked like this:
2012-03-14 17:22:31.809
I was unable to find how to format this particular date, since nearly all documentation of dates gives an example of a time without milliseconds. The API documentation states:
 u     Decimal fraction of a second                                              
Examples:
(minimum 1 digit, arbitrary number of digits allowed)         001 (i.e. 0.001s) or
100 (i.e. 0.100s) or
99 (i.e. 0.999s) or
999876543210 (i.e. 0.999876543210s)
 
Nope, this didn't work.

After searching around and trying nearly every letter in the alphabet, it turns out that you need to use ms for milliseconds. Your Date format should look like this:
Y-m-d H:i:s.ms
Hope this helps someone else!!

Friday, August 12, 2011

Proper Indentation on a Tree In ExtJS

I'm using ExtJS's tree functionality to display navigation on a website (and then skinning over it so that it doesn't look like a bunch of folders).  However, a major problem that I was having was that ExtJS absolutely does not allow multiple lines in its tree implementation.  You can update the stylesheet to allow for wrapping with the following entry in your CSS:

.x-tree-node-anchor {
	white-space: normal;	
}

However, this will cause your multiple lines to wrap without the proper indentation.  I struggled with this for many hours before finding an excellent extension that wraps properly.  You can find it here:

IndentedTreeNodeUI

Mad props to JJulian for putting this together!  Hopefully, my links to his page will make this UI easier to find.

Sunday, February 7, 2010

Extjs: JsonStore will not load

I spent a lot of time trying to figure out why my JsonStore wouldn't load into my EditorGrid. No errors were being thrown in Firebug, unless I used loadexception() on the store, in which case the exception really wasn't much help.

Finally, I figured out the problem. Can you spot it?

var js = new Ext.data.JsonStore({  url: 'myurl.jsp',
sortInfo: {field: 'name', direction: 'ASC'},
baseParams: { elementid: '1' },
reader: new Ext.data.JsonReader({
root: 'elements',
id: 'id'
}, [
{name: 'id'},
{name: 'name'}
])
});
js.load();

If not, maybe you are having the same problem I was.

Apparently, when you create a JsonStore, it creates its own JsonReader. So, if you specify a JsonReader, it will ignore yours and use the one it created. By changing the store to Ext.data.Store, it fixed the issue.

A simple fix!

Friday, February 5, 2010

Extjs: XML Tag Name Mismatch

I'm using FileUploadField.js in Extjs. It was working, but then I changed the URL to which I was submitting the form, and then started getting the following error:

XML tag name mismatch (expected br)

This was curious, and I couldn't figure out what the issue was. I googled and found very little help on the subject.

The solution? The problem was in my back-end server code. There was a null pointer exception in my Java code, which returned an HTML error page that is standard for our app. The Extjs processing was expecting JSON, and couldn't find it, obviously. Hence, the error.

If you are using Firebug (which you should be, everyone should be), you will be able to trace the error better by looking at the "Net" tab when you access your Extjs component that is throwing the error. After that, it was an easy fix.

Tuesday, July 14, 2009

New Project: CAS 3 w/Weblogic 9.2

It's been a while, but I'm sure that there are shenanigans afoot since I'm starting a new project of implementing CAS/Acegi (Spring Security) with Weblogic 9.2.

Friday, August 22, 2008

Issues with CVSNT - Switching Between Unicode and Ascii

Problem: Using TortoiseCVS, a developer somehow checked in a bunch of SQL files as Unicode. I am nsure what exactly the developer did to do so, but likely it was caused by right clicking on a file when adding it to CVS and randomly selecting options from the "format" and "keywords" menus there. Who knows.

As the files were checked in and checked out of CVS by various developers, the files became more and more corrupted, merges were difficult, and the developers were unable to do their work without searching for random Unicode characters in the files and deleting them. In addition, CruiseControl stopped recognizing changes to files for updates.

Solution: A command-line interface needs to be used, I was unable to find a resolution with the CVSNT GUI interface.

  1. First, CVS.exe needs to be in your windows path. This was already done on our server because of CruiseControl and ANT using it.
  2. The command from a windows command line is:
    cvs update -kkv
  3. Once you have done this, you can use CVSNT to commit the file. If you do not commit, the changes will not be made. HOWEVER, you cannot commit using standard CVSNT means (TortoiseCVS). You need to right click on the file, select "Command" and enter the command commit -f
  4. The -f on the commit is absolutely necessary.
That's it!

Wednesday, July 9, 2008

Fumbling with JAWIN

Currently, there is no quick and dirty way to use opensource Java tools to convert Word Documents to PDF. So, to do this task I've been using BCL Technologies' Easy PDF. Since this application is written as COM, a java to COM bridge is necessary to use the SDK with Java. With Easy PDF 5.0, I had set up my own method of using the opensource tool Jawin to do this bridging. Now, I'm upgrading to Easy PDF 5.1 and they have a Jawin Java build included in their build, which I was pretty excited about. However, they built the jar with Java version 6, which I cannot use as we're stuck with Java 5 since we are dependent on Websphere (why would you not include more than one build with different java versions anyway? Whatever).

Since I had used Jawin before, I decided to attempt to do what we needed to do with Jawin, Java 5 and Easy PDF 5.1. The initial backwards compatibility with our code that was using Easy PDF 5.0 was smooth and simple - the build worked the same as I'd done before and no code changes were required.

Moving on to the new requirements, which is why we're upgrading Easy PDF. We needed to utilize additional features - merging two or more PDFs into one, splitting one PDF into two, deleting pages from a PDF, adding a watermark to a PDF. I rebuilt the code with Jawin to use these new features. And, there were difficulties. This is more of a complaint about Jawin than about Easy PDF.

Jawin is a great idea and on the surface (at least for my purposes), easy to use. However, the current version is an alpha version, and hasn't been released in several years. The real problem using it came from trying to use the Variant object. Documentation for how to use this object is spotty. Examples in the sample code are non-existent. Internet searches brought back a couple of threads, but most were just people asking the same questions that I had and not getting any answers.

Trying to create a Variant object was my first problem. I ran into multiple issues, and I was simply trying to pass something an array of Strings. That should not be as difficult as it was. I did get the "org.jawin.COMException: 8000ffff: A VT_VARIANT must be combined with VT_BYREF (base vartype 12)" yesterday, when trying to use myvariant.vt = VarTypes.VT_VARIANT or even using VarTypes.VT_BSTR, which is what I thought I was supposed to be doing. It is difficult to comprehend WHY we are putting things into a stream in order to make them into a variant, and how to get them out again.

So, I finally followed this guy's advice, which I found this morning. I overrode the class that was generated by the type browser. Instead of creating a method that accepts a Variant that is an array of strings, I created a method that just takes an array of strings and still invoked in the same way that Jawin was doing. And guess what? It worked! So, why does the typebrowser create the Variant method in the first place?

I wish the Jawin folks would continue to work on their project and get some of these bugs fixed. It's a great product with a lot of hope, but it needs help and it needs to be more user friendly to those java folks out there who don't know COM.