Monday, November 1, 2010

JasperReports & the Format Factory

The more I work with JasperReports, the more I admire the project altogether. It seems like every time when I'm like "I wonder if JasperReports can handle that" it does, and it does it well.

Recently one of those issues had to do with localization, specifically date & number formatting. If you have worked with JasperReports you'll probably know that you can format dates & numbers with the pattern (e.g. "MM/dd/yyyy") attribute on a text field element. That is just fine when the pattern is known at design time. But what do you do when the patterns need to be localized or in other words dynamic?

No you can't use a String parameter as a pattern. The pattern attribute on a text field does not accept an expression, only a string literal. Another solution might be to have your application twiddle the JRXML and inject the proper patterns. But that would be hacky and could easily be error prone.

Enter the Format Factory. The Format Factory concept is simple but powerful. The FormatFactory is an interface in the net.sf.jasperreports.engine.util package that you implement to create your own date & number formats.

public class MyFormatFactory implements FormatFactory {

public DateFormat createDateFormat(String pattern, Locale locale, TimeZone timeZone) {
//create your date format here
return your-date-format ;
}

public NumberFormat createNumberFormat(String pattern, Locale locale) {
// create your number format here
return your-number-format ;
}

}

Essentially, your application takes over format creation instead of the JasperReports engine itself.

The best part of all this is your ability to create formats based on your own defined constants. You'll notice that the two methods in the class above have a "pattern" parameter. That is the pattern that you assign to the textfield.

You might say, hey I thought we weren't using explicit patterns anymore. You're right. But, we have to give a hint as to how the textfield needs to be formatted, so we would use format constants (e.g. SHORT_DATE, LONG_DATE, TIMESTAMP, etc). The constants are assigned to our text fields pattern attribute and get passed to our FormatFactory where we determine how to create a formatter based on those constants. Kinda cool, eh?

You might also notice the timezone & locale parameters in the methods above. Those are also parameters you can pass into the report itself which in turn get passed in to the format factory to assist you in creating the appropriate formats. For example, when you create a date format you'll need to know the time zone since that is an important part of actually formatting a date.

The Format Factory is a fantastic feature. This is especially true for large applications that already have formatting logic implemented in the application allowing you to reuse your existing format logic.


Friday, May 14, 2010

Thoughts on Flash from Jobs

So I just happened to log onto Apple's site today and noticed this article on Flash by Steve Jobs:

http://www.apple.com/hotnews/thoughts-on-flash/

So in summary here is why Flash isn't going to be on iPad, iPhone & iPods.

1) Flash is not an "open" standard
2) Apple mobile devices can already access tons of video content
3) Flash's reliability, security and performance on Macs is not good
4) Battery life
5) Flash and touch interface not a match
6) The dependability of a third party between Apple and developers

This sounds reasonable to me but I wonder if there still aren't other behind the scenes reasons. I'm sure Apple wants to collect all revenue through the App Store. What do you think?

Tuesday, January 26, 2010

Learning Spring

I am officially starting to learn the Spring Framework. Until recently the projects I have been working on have not been using Spring so I had no driving reason to learn it. Since I am so busy with school (WGU) & work there is almost no way I could learn it unless it is involved in one of my projects. Now that I am involved in a project with Spring, it is a great way to learn it.

I am starting to wrap my mind around the central idea of the Spring Framework which is Inversion of Control & Dependency Injection. Now that I'm starting to understand the framework, I realize that it truly is a great idea. In prior development I always had thoughts about the tight coupling between different areas of the application and wished I could do something about it.

Not that Spring wiring isn't cool enough, but Spring also includes some other very cool features such as Data access support, job scheduling, mail support, web flow, etc.

So I'm looking forward to getting a deep understanding of Spring & getting an app working from scratch with Spring.

Wednesday, November 25, 2009

Independent Software Consultant

As of October 2009 I am (drum roll) an Independent Software Consultant. The "Independent" part is because I am not attached to any particular business entity and I will be marketing my skills as an individual. See my website at www.rogerdiller.com. I have chosen the independent route mainly because I am a full-time student... it's just not possible to hold down a full-time position and still have adequate time to study. I don't know exactly what route I'll take after finishing my degree... it depends on a variety of factors.

As far as work, I have had the privilege of working with some great new clients in the last couple months and have been expanding my skillset much to my delight! :-) Most of my new work in the last couple months has involved the ZK Ajax Framework. Of course I am very pleased being that I am a big supported of ZK (when is the world going to wake up to ZK?!). Here are some new things that I have been delving into: Web services (Axis2,GroovyWS), Spring, and ZK Web Flow.

School (WGU) has been going great as well. I love the competency based model of WGU. I am able to simply study the areas that I am not as familiar with and upon passing some pre-assessment exams I can take the final exam and move on. Currently I am scheduled to take my first 2 exams next week. Hopefully all goes well. :-)

Overall I have more than enough to do. Between juggling projects and studying as much as possibly there sure is plenty to do.

Friday, October 2, 2009

WGU is good stuff!!

Well yesterday I started on my BS in Information Technology degree program with Western Governors University and I must say I'm very impressed! Everything is very straightforward and intuitive. I started with the required first course for all new students which is called Education Without Boundaries (EWB). It was a very informative course (I completed it today) which gives you a ton of information about the school, study strategies, time management skills, etc.

WGU has created a very good environment for learning. You are assigned a mentor for your entire time there and also have mentors for the individual course you study. There are communities where you can meet other students, ask questions or whatever you feel like. WGU even has their own instant messenger to communicate with other students, mentors, and to join into live discussions. You have access to tons of information, books, articles, magazines, you name it. You can get books sent to you on loan. Something I found very cool was you can get access to lot's of software for cheap or free. For example I can get Windows 7 Pro for $30!

All in all even though independent learning is not for everybody, I think a lot of people could find the WGU experience enjoyable.

Stay tuned... I intend to continue to blog about my educational experience as I study with WGU.

Tuesday, September 8, 2009

Learning TDD, BDD

In the last couple weeks I have dived head first into automated testing, specifically Test Driven Development or TDD. It's been quite the journey so far. At first TDD concepts seemed hard to grasp but a balance of reading and video began to bring it together for me. For example the idea of only writing code to fix a failing test is a hard one to grasp when you have spent almost 3 years developing code without even thinking about a test. It was hard to think in terms of what a "unit" test is not. Borrowing from Michael Feathers blog:

A test is not a unit test if:

  • It talks to the database
  • It communicates across the network
  • It touches the file system
  • It can't run at the same time as any of your other unit tests
  • You have to do special things to your environment (such as editing config files) to run it.

  • Writing tests around legacy code is another big challege. Being that my project is defined as legacy code because it doesn't have unit tests, I have the task in front of me in getting it covered by tests. It won't happen without quite a bit of refactoring!

    I watched a video on Behavior Driven Development or BDD. It is essentially doing TDD well. The focus of BDD is focusing on testing the behavior of a system not necessarily having your tests mirror the exact structure of the classes you are testing. In this way your tests become the specification for your production code.

    Here are some points/tips I've observed:
    • Testing first helps you to think critically about what you are trying to write.
    • It is impossible to know everything upfront. Do what you know now, thinking decently far in context but not to far.
    • Don't over engineer.
    • Agile & TDD allows for tight collaboration with the customer... a good thing!
    • Tests are the "glue" that holds an application together.
    • Unit testing is testing the smallest components which are classes/methods.
    • Customer is in control which is very motivating for them.
    • Solve the RIGHT problem RIGHT!
    • Over the long term effort required to write tests will pay off vs having to maintain untested code.
    • Developer can feel confident about work.
    • Refactoring is changing structure without changing what the code does.
    • Keep unit tests as simple as possible.
    • Tests are atomic and isolated.
    • Create "test list" from requirements, from this we can know if we are "there yet".
    • Tests are like examples.
    • Concentrate on testing the behavior of your program not necessarily mirror the exact structure of the class you are testing.

    All in all I believe TDD is a superb idea and a process I am adopting in my projects.

    Life Update:
    In my last blog post I wrote about moving and pursuing a degree. We arrived in Gosport, IN on August 4. Originally I was planning on starting school on Sept. 1 but since our apartment was not quite ready I pushed it off another month. So I am scheduled to begin my degree program on Oct. 1 with WGU.

    Monday, July 20, 2009

    Moving and Pursuing Education

    So since I wrote my last blog a lot of new developments have taken place. For quite some time I've been wanting to get my Bachelor's in C.S. and finally that dream is taking form. A couple things that have kept me from moving ahead with a degree is cost of living while earning degree and a real solid reason for doing it other than for just personal gratification. We are solving the cost of living problem by moving to Gosport, IN and living on our relatives property in an apartment type setup. I will still be doing part time development for my current company which will provide us the funds to pay for our expenses and hopefully enough to cover the cost of education. As far as a real reason for earning the degree it seems like in the software field the need for at least a Bachelor's degree is becoming more and more of requirement. After talking with several people it became very clear to me that this was what I needed to do. So if everything continues to move along smoothly we will be moving August 3,4 and on September 1 I will be starting on my degree with Western Governors University (www.wgu.edu). The main reasons I choose this school is because they are competency based and relatively low cost. All of my experience that I have gained in the field will help me get through faster. They charge at a flat rate every 6 months so the more aggressive you are the less you will need to dish out. So I'm very excited about increasing what I know and getting a more rounded out and broader education!