Understanding the beauty of JSF

Apr 3, 2014

My web framework of choice is Ruby On Rails. It’s perfect for me. Not because of its scalability or performance, but because of its architecture. You do not need to do lot of work to create a website or a webservice. Ruby Gems have all the power you will ever need. Ruby itself allows you to do even a black magic nicely.

It’s true to say that i am a RoR fan.

So when i started learning JSF i thought Gosh! It’s ugly! It’s totally impossible to work with!. But in a while i realized that small yet mighty concept, i even did not imagine to be thinking of.

See, when you write a website, you need two things to be done:

  • give a user static content; user just should see something on a display!
  • take user data, process it and perform previous step; in order to make a dynamic website (which is 90% of all the websites you’ve seen, i guess) you should use web forms and process them

The last thing i did not mention here (because i did not dive in it yet) is: just use that javascript. You would never provide user-friendly interface on the web until you get full control of what’s going on client’ side. That’s the purpose of JavaScript. Different hints and tips, asynchronous operations, messages and other cool stuff making your UI looking great is the JS part.

But in other cases you use resources. That’s the bundle of data, stored (maybe) in database and being controlled by user via the forms.

Any form (yes, just any) could be described as relying on some resource. Login form? It uses User resource. Search form? It uses the SearchQuery resource. Post creation form? It serves Post!

So, that powerful concept i was talking above is the principle a Managed Java Bean describes the Resource wired to the User Interface.

See, when you show a form to a user - you get your database row maped onto a Java Bean. When user saves the form with the new data - that data gets stored in the same Bean and the method you’ve set to commandButton or whatever is invoked.

Just think of it! You are doing exactly the same with all those Rails, Play, Django or any other web framework, when you are creating a dynamic website!

JPA with SQLite autoincrement troubles

Apr 3, 2014

Today i’ve got an exception when JPA was trying to insert a new row to a table.

My model definition was like this: ```java @Entity public class Merchant { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private int id; private String name; // ... public Merchant(){ } // ... ```

And the table creation script was the following: ```sql CREATE TABLE MERCHANT ( ID INTEGER PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, BANKNAME TEXT NOT NULL, SWIFT TEXT NOT NULL, ACCOUNT TEXT NOT NULL, CHARGE REAL NOT NULL, PERIOD INTEGER NOT NULL, MINSUM REAL NOT NULL, TOTAL REAL NOT NULL ); ```

I faced some strange exceptions like id could not be null, SQL error or missing database (near “values”: syntax error), etc.

The solution to this consists of two steps:

  • in database: remove the AUTOINCREMENT and NOT NULL annotations from the ID column as SQLite will automatically increment its value (in DB)
  • in entity’ code: remove the GenerationStrategyType from the id member annotation

incompatible character encodings: UTF-8 and ASCII-8BIT

Aug 16, 2012

Just got the following error in my Rails project (Rails 3.2.6, Ruby 1.9.3):

ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT)

That was caused by the case when MySQL record (ActiveReciord object, actually) contained UTF-8 characters and i was trying to output those chars in my template. But mysql gem does not support those. It needs some hacking.

Luckily, there is more convenient way to solve the problem. The solution of this issue now appears too easy:

  • Install the mysql2 gem
  • Use adapter: mysql2 instead of adapter: mysql in your config/database.yml file

My coursework. Two months later

Apr 23, 2012


My coursework: two months later. No, i was not doing all that stuff for two months - i… “freezed” the project for that time =P Actually, the greatest portion of job was done in one day - 22.04.2012 .. 23.04.2012 =)