Thursday, July 28, 2005

Frank's Blog

It is always annoying to find out halfway through a task that there is a better way of doing it. In this case I found out about XHConn.js, a nice javascript class for doing Ajax calls. It is a much cleaner way than I was planning so I can throw away my old template file and start writing a new one. When that is done I can finally start to think about adding some new functionality.

Wednesday, July 27, 2005

success with xdoclets

I am happy to report a lot of success with using xdoclets. I have now written a template that generates most of the JavaScript necessary for hooking the formBean with an ajaxForm in the jsp or html page. I decided for the moment to keep it simple and not use any of the merging functionality of xdoclet to inject the onLoad function straight into the jsp

Tuesday, July 26, 2005

Writing new XDoclet tags

VECNA Technologies : What We Do contains all the information necessary to write taghandlers and subtaks. I can do most of what I want using the standard templates method. The biggest problem is that using the standard template tags I can not see a way to create a simple comma-delimited list of all the properties defined in my forms.

The cleanest way to achieve this is obviously writing some taghandlers, what is what I am now doing. This link seems to tell me exactly how to do this, so I am off to write it.

Monday, July 25, 2005

XDoclets, AJAX, JavaScript, Struts and MyEclipse

I have noticed very quickly that writing AJAX applications is getting messy fast. A lot of the code to write is very standard, and it is very easy to make mistakes. I do remember the same kind of problems with EJB's, and how XDoclets solves most of those problem. I have been looking quite intensively on the web to find if somebody has used XDoclets for AJAX, but could not find any solution.

So I am thinking of cooking my own XDoclet solution. I want to be able to put XDoclet tags in a Struts Form which
  1. Generate a JavaScript file.
  2. Add a function that sends a AJAX request from the webpage
  3. Add a function that handles the response
  4. Add a function that adds the form HTML to the document
  5. Injects an onLoad function inside the body function of a specified HTML 0r JSP file
  6. Injects the JavaScript file descriptor in the header of the same file
I have had a lot of problems getting some good information on the web, but this OnJava article gives some good clues. I have been experimenting with the MyEclipse IDE and I am going to test if I can get this to work. I'll be reporting back

Some more on bookkeeping

Just as a reference:Double Entry Bookkeeping. I have simplified things because I decided that a peron doesn't have an account, just a net value. To be consistent, one needs to follow this page, but I want to keep an individuals' accounts, not a company's.
One of the first hurdles I ran into was the fact that MySQL by default does not use referential integrity! It does not use foreign keys and other concepts. This was a big problem for two reasons. Firstly it violates the lazyness rule: I do not want to be responsible to guarantee the integrity of the data. It clutters up your code, and any bugs lead to potentially large amounts of data being wothless. I just want to handle errors where the database tells me I am doing something wrong, leaving the database consistent. Secondly, the MyEclipse Hibernate mapping tool uses keys to build its mapping xml files and generate the Java objects. No keys, no one-to-many and many-to-one types. A way around is to write the mapping files myself, and let Hibernate gernerate the schema, but I really do not want to learn this while there are perfectly decent tools to generate them automatically.

So, for referential integrety to work in MySQL it is critical to use InnoDB tables. A simple howto I found at Referential Integrity in MySQL, lthe MySQL manual is also very useful. I love the way users can enter their own comments. I will probably optimize my server for the InnoDB.
I have progressed quite a lot over the last two weekends. As always, the most important thing in the beginning is getting the concepts right! Since I don't have much technical knowledge of bookkeeping, and started out with a hazy knowledge of double-entry bookkeeping I got a lot of the database modeling wrong when starting out.

I figured the concepts out (reinventing the wheel no doubt) and translated them into computerse. A quick summary.

As a shorthand, I use money for the concept of value. Money can also be shares, for example, but since we can assign everything a monetary value, money is a good shorthand for this.

For bookkeeping purposes, money is like energy: it gets destroyed nor created, it just moves around. Every object or concept in this world has got an account associated with it, which has debit and credit side. When you spend money, it is an entry at the debit side, when you earn money it is an entry at the credit side. The account balance is the difference between credit and debit. Because money is never destroyed, any change in the balance of an account must be balanced by another account.

Each person has assets, and liabilities. Examples of assets are bank accounts, shares, houses, etc. Examples of liabilities are loans, mortgages, credit cards, etc. Each asset and liabiliy has, as previous stated, an account. The person's net value is the difference between the balance of assets and liabilities. Each person has income which are a set of accounts that increase her net value, and expenses, a set of accounts that decrease her net value.

The debit side of the income accounts represent her income, the credit side represents money she will get in due course (this is a handy concept later for interest calculations and projections). Quite often the debit side is unknown, so the debit stays zero. The credit side of the expense accounts represents her spending. I haven't found a good concept for what the debit side represents. Money that will be spend in due course? I'll think about it.

A movement of money that changes her net value is a transaction. A movement of money that leaves her net value unchanges is a transfer.

These concepts make understandable: income balances are negative, and expense balances are positive. A creddit card is a liability, so using it increases a credit card's balance. Suddenly my bank statements became a lot clearer. I bet 90% of the readers will shake their head and mutter that all this is obvious. Well perhaps, but it cost me some thinking to get this sorted out clearly, and in such a way that I can represent it in a database.
This is an ongoing attempt to blog my developing of an bookkeeping webapplication. It is a learning excercise, both on the technical and project front.

A short overview: I want to refresh muy knowledge on several techologies I know, and learn some new ones. In no particular order:

  • XHTML: I want to use strict XHTML webpages, and refresh my knowledge of all the tags

  • CSS: I want to thorougjly learn CSS to style my pages. I know the fundamentals, but not in-depth

  • AJAX: building interactive web-sites without having to clicl the Submit button all the time:

    • Javascript: necessary for modifying the web-page. The interaction between JS and CSS is particularly interesting

    • DOM: traversing and manipulating the Document Object Model.

    • XMLHttpRequest: Sending requests witthout disturbing the user's workflow

  • Struts: environment for building webapps. I was really hesitating to go for Java Faces, but Struts is more mature, and we use it at work so this is more relevant

  • Hibernate: excellent way of building and OO layer on top of the persistence layer (i.e. the database)

  • MySQL and SQL: refreshing my knowledge of SQL is not a bad thing.
  • Eclipse and MyEclipse: MyEclipse is the only bit of non-open source I am using, but again, we use it at work, and the tools seem excellent