Showing posts with label Vaadin. Show all posts
Showing posts with label Vaadin. Show all posts

Sunday, February 20, 2011

Springing DAO: Spring + Hibernate (Part 1)

So now that I have a rough idea I could get this puppy to code. We are winging it after all. Then again, software development is really like this. Hey, I have made projects with even less.But lets got get ahead of ourselves. Before we write anything, we have to deal with the database design.

Now about the database, I am using the MySQL that comes with XAMPP. Its free for the download and it already comes with phpmyadmin. I know I can do this "old school" and go command line but who needs that aggravation. Masochism isn't really my thing.

Using phpmyadmin, here is the schema.
Figure 1 Our project database schema


*Now if you say this can't be done just by using phpmyadmin alone then apparently you are using it wrong.

The design is quite straight-forward. There are four primary tables:
  1. User Table - contains the log-in and password recovery data. Its support tables of role and user_detail is quite easy to figure out.
  2. Request Table - handles all the request generated by the users. It should be noted that creating a request doesn't mean you automatically have an "approved" avr reservation.
  3. AVR table - contains the available AV rooms that can be reserved. The "isAvailable" flag is used if the AVR can be reserved and is not under repair or something.
  4. Status table - it tracks the state of the request. If you can recall in my previous post, the flow chart logic is on this table. On a side note, the "set_by" field should be linked to the user table via a foreign key.You should be able to figure that one out.
Stay tune for part 2 when we actually starting writing code.

Saturday, February 5, 2011

What exactly are we up to?

First thing first. We have to agree on a couple of points:
  • I will be using Netbeans for this - you could use Eclipse if you want.
  • We will be using MySQL
  • We are going to make a web application using Vaadin
So to start off by setting up our environment. What we are going to need are:
Download it, copy it off someone whatever. The sooner you get the stuff into your dev machine the sooner we can talk about what exactly are we up to?

Figure 1.0 Installing the Netbeans Vaadin plugin

Have it? Installed it? Good.

What we are going to build/make/develop is a facility-reservation system. So what exactly will our "FRS" application be doing? Here are our requirements:
  • All reservations must be submitted and processed online
  • Must have AAA type security
  • Granular user permission system
  • Resolve scheduling conflicts
  • Track histories like facility usage, request status, room schedules, etc.
  • Have a basic set of reports (exportable to PDF)
Figure 1.1 FRS Flow Chart
Our FRS web application is not that complicated. Take a look at the flowchart. A request is made. The request data is quite simple. It contains the facility being requested, when its to be used, how long its to be used and for what purpose. The request is of course submitted by a user authenticated by the web application. Anonymous users can't submit make a reservation request. The request is then evaluated by someone with higher privileges say an administrator. The request is then either disapproved, approved or rescheduled (or  reallocated). The request once approved does not end the cycle. It only ends when the request is carried out. This is done by a different role or class of user.

We will talk about the database design later in this series.

Thursday, January 27, 2011

Vaadin is what exactly?

If you talk to a Finn, he will tell about Vaadin being a mythical creature in Finnish folklore, the goddess and divine ancestor of the mountain reindeer. They even got a song about it.

Interesting, but not the Vaadin we should be thinking about.

Now if you go to Wikipedia, it defines Vaadin as:
"Vaadin is an open source web application framework for rich Internet applications. In contrast to Javascript libraries and browser-plugin based solutions it features a server-side architecture, which means that the majority of the logic runs on the servers."
Technically correct, but it doesn't exactly tell you what to expect when programming or developing a web application using Vaadin. You read that right. Vaadin is for creating web applications - Rich Internet Applications if you want to be an ass about it. The key thing with Vaadin is that it allows you to make these web app without writing a line of HTML or CSS. Ok, you can write HTML and CSS, but only if you really, really want to. Take a look at its design.

General Architecture of Vaadin

The architecture of Vaadin allows you write Java code as if you were creating a AWT, Swing or SWT application. You heard me! You don't have to write a line of HTML, CSS or even JavaScript. Because HTML, JavaScript and the other browser crap is hidden away, you won't be wrong in thinking that the web browser as a thin-client terminal or platform. Still not buying? Well, let's move on to an example. In the long tradition of hello worlds (if you don't get it, then you suck as a programmer), here a Vaadin "Hello world":

 import com.vaadin.ui.Window;  
 import com.vaadin.ui.Label;  
 public class HelloWorld extends com.vaadin.Application {  
   @Override  
   public void init() {  
     Window main = new Window("Hello World");  
     setMainWindow(main);  
     main.addComponent(new Label("Hello World!"));  
   }      
 }  

That's it. No HTML template, no JavaScript. Here is the screen shot of web app after it has been compiled and deployed.


That shouldn't be that hard to figure out. I just wrote Java code, a very short one and made a working web application. Can you spell chuyness?

Wednesday, January 26, 2011

Swing-like Chuyness (My Vaadin course of beginners)

It's that time of the year again where I had to teach yet another batch of students. This time I don't think I'll be doing Tapestry5 again - You don't repeat the same gag, to do the next one. So, what is the next gag? This time around it's Vaadin. I wanted to learn how to use Vaadin ever since a former student of mine showed it to me. So, I plan to build something using Vaadin and take my students along for the ride. 

Like my Tapestry course, I will walk you through a complete web application development from design to deployment using the Vaadin framework. I think you should read "walk you through" like "we will be winging it". Making good lesson plans isn't really one of my strong points.

The course will look like something this:

  1. Vaadin is what exactly? 
  2. What exactly are we up to?
  3. Springing DAO: Spring + Hibernate
  4. Breaking Tradition: GUI programming for webapps
  5. Tweaking out! 
  6. Coming back alive: Deploying for WAR
This isn't exactly set in stone, more like something I just pulled out of my ass. So if there's something missing, we will deal with it when we get to that bridge. We will make up the requirements and specification as we move along.

Sunday, November 7, 2010

SpringHibernateVaading

A few weeks (maybe a couple months ago - SO SUE ME!), I figured out how to get a Spring WebApplicationContext into a Vaadin application, so I tried to figure out how to get Hibernate into it with a working DAO to boot. It took a few hours but I think I have this puppy wired. Get it?

Here's a screenshot:
singgihpraditya blog help me get the bits working together. Spring Framework breaks your application into small bits and wire them together using XML config files. So, the magic is really in the config files.

Now since I am using Netbeans as my development IDE, I didn't have to deploy a mySQL database for this. Netbeans has a since Derby "Sample" database - being a sample it already has data.

Don't forget to import the derbyclient.jar. It took me a few to figure that one out. The first time around I thought that my database properties file was source of the error along with the Spring config file.

Here is another screenshot with the web application running on Tomcat.


Aryan, Bhadz, Cholo, Carl, Kim don't hate!

Friday, September 3, 2010

Playing with Vaadin + Spring

A few weeks ago, I stumbled on Vaadin Framework and it came with a catchy tag-line:
Vaadin is a Java Framework for building modern web applications that looks great, perform well, make you and your users happy.
That got my attention and so like a kid with a new toy, I started playing around with it and try to do stuff with it. It took me a while, read a few blogs but I have managed to get the hang of Vaadin and even got it to work with Hibernate and Spring. Vaadin with Hibernate was easy to figure out but Vaadin, Spring and Hibernate along with a DAO was a bit of a bitch of figure out but I eventually did. Nicolas Fränkel's blog gave me new insight on how to approach the problem. I sort of agree with his opinions on how to get Vaadin to work with Spring as compared to the techniques posted in the Vaadin wiki page. To quote Nicolas:
The first one uses the Helper “pattern”, a class with static method that has access to the Spring application context. IMHO, those Helper classes should be forgotten now we have DI since they completely defeat its purpose. If you need to explicitly call the Helper static method in order to get the bean, where’s the Inversion of Control?
The second solution uses Spring proprietary annotation @Autowired in order to use DI. Since IoC is all about decoupling, I’m vehemently opposed to coupling my code to the Spring framework.
 The trick was understanding how to isolate the Spring Context from the Vaadin application. With them separated, all that was needed was configuration files.

The thing was not to forget to configure the listener in web.xml file:
 <listener>  
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
 </listener>  
 <context-param>  
     <param-name>contextConfigLocation</param-name>  
     <!-- <param-value>classpath*:WebApplicationContext.xml</param-value> -->  
     <param-value>WEB-INF/WebApplicationContext.xml</param-value>  
 </context-param>  

After that the WebApplicationContext.xml file in the WEB-INF folder.
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>  
 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"  
      xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"  
      xmlns:p="http://www.springframework.org/schema/p"  
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
                  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd  
                  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd  
                  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">  
      <context:property-placeholder location="classpath*:*.properties" />  
     <context:annotation-config />  
     <!-- add autowired or explicitly configured beans here -->  
     <bean id="myVaadinApplication" class="edu.chuybook.app.MyVaadinApplication"/>  
 </beans>  

With that, you can start doing some really interesting stuff!