Friday, February 26, 2010

Modal Panel & z-index value

I've been using modal panel without understanding what a z-index is. It's a CSS property that I didn't have to worry about until recently. Apparently, a z-index value in a component can affect the way components are displayed. The definition of a z-index from w3school is :

the z-index property specifies the stack order of an element.

An element with greater stack order is always in front of an element with a lower stack order


So, if you have two named mp1 and mp2, each of which has a z-index value of 2000 and 1000 respectively (those are arbitrary numbers that I picked), when you called those two modal panels, mp1 will always display on top of mp2. You will be scratching your head as I was, if your mp2 is smaller than mp1, and trying to figure out why mp2 wasn't showing up. The reason is because of your z-index value. In using I don't think you need to specify z-index value explicitly. If you didn't specify any value for z-index and called mp2 from mp1, it'll still display properly.

Showing a process bar panel inside a rich:modalPanel

So, I have been complaining about RichFaces AJAX a lot. The more I get to use most of its features, the more I find that AJAX is not as "agile" as we think. There is one components of AJAX that I really dislike of. It's .

is good if you have something like a warning to display. But if you want to do more such as adding a form onto the , it can give you a hard time. I am not going into length about how it caused me troubles. I'm going to talk in this post about how I called a modal panel inside another modal panel.

So, I have this first modal panel (let's call it panelA) which contains a select one radiobox and a commandButton. So, it's a very basic form where users can make a choice and click the commandButton and in the background, all the events are happening. After the method is called, the page is refreshed with new information. So, the method() in my commandButton is not a very lengthy one. But, depending on the connection, it can take slow and often cause timeout to the users. So, I want to add an indicator that shows that there's something processing in the background and during the processing period, I don't want to let users do any type of additional processing.

Since calling modal panel is mainly done by using javascripts, I tried using onclick and oncomplete attributes of the commandButton. But for some reasons, it didn't work. So, here's what I did in the end :

So, with the help of and , I managed to call another modal panel from inside a modal panel.

If you have a page with multiple method calls which can take long time, I would suggest you to follow the techniques mentioned in here.
http://community.jboss.org/wiki/RichFacesPleaseWaitBox

Wednesday, February 24, 2010

RichFaces AJAX & Problems

AJAX is a technology that has been advancing far more rapidly than any others. Most of the web applications these days make use of AJAX.

AJAX is Javascript based. So, a programmer has control over a page without really having to know too much in details about Javascript. It has made AJAX a popular choice for those who want to make use of Javascript but hate to learn it.

Using AJAX together with dynamic HTML make your web pages more stylish, appealing & sleek. Because you can update the view according to users' choices, it is much easier to do the customization of the pages.

Recent development in AJAX technologies has incorporated other features and hence made AJAX based framework a better choice in creating web-based applications where MVC structure is used.

I use RichFaces which is a framework that combines JSF & AJAX. Even though RichFaces provides us with all of the advantages that I aforementioned, AJAX is not necessarily the best solution sometimes. Why? I can list a few complaints here.

It is true that AJAX makes customization a lot easier. But it has a price on the side of performance. If you make a lot of AJAX calls which update the pages, depending on the way you interact with the page, it can cause troubles. In my cases, I have experienced lost of data because of multiple re-rendering of one page. In fact, troubles with RichFaces are big ones. If you do not prevent from multiple methods being called simultaneously, you are likely to run into the conversation timeout error. So, when you design your application, you need to make sure that a second method is not called unless the first one finishes.

RichFaces is good but let's face it. It's still built on top of Javascripts. So, if you want to change something in depth, you still need to learn about Javascripts. If you look at a lot of RichFaces tags, you can still see that their attributes still make use of a lot of Javascripts.

I'm not saying that you should totally avoid using RichFaces AJAX. Just be aware that there're some pretty serious downsides to it once you start using it a lot.

Tuesday, February 23, 2010

Why people are addicted to Facebook

I attended a talk about two weeks ago by a prominent professor at Columbia University. The talk was about Freedom in Cloud Computing. I decided to attend the event because I thought I might learn something valuable from the talk. Cloud computing has been a part of our lives more or less. Even though it hasn't taken its full form, it'll in a very near future. It's passed the early stages of development and entered the mid-renaissance stage. But the talk wasn't really about cloud computing. It was about the destruction of our privacy by incorporating cloud computing to our daily lives. The professor who gave the talk was one of the important figures from the group of Software Freedom Law Center. Obviously, he hates facebook and twitters. He thinks those applications have been exploiting our privacy by monitoring the usage logs which contain some personal and confidential data. His method of preventing such privacy invasions is by creating the so-called mini portable servers, which can be controlled by only us, not the giant application developer such as Google or Facebook. In theory, it sounded easy and feasible. But in practice, I personally think that it will take quite some time.

I have a couple of friends who use Facebook a lot. I don't like Facebook and I don't like Google. But I am a Google client because of the Google chat which is the only way I can connect with my family.(Other messaging clients are not allowed in my country). I have nothing against Google so far. But Facebook got me annoyed about some privacy issues and hence I deactivated mine. And I haven't had a single regret yet. But I am constantly amazed by the ways in which people are addicted to Facebook and in which people can so easily reveal about one's self and one's innermost feelings and secrets. And I started asking myself why is it that people can share thoughts on sites like Facebook & Twitters, but not in person. Sharing thoughts on Facebook is like distributing your diary book to your classmates. Granted you can control those privacy settings but how much can you really control?

I do have a couple of explanations for why people prefer Facebook and emails over phone calls.

First, it's very convenient. People are self-centered. If you want to talk to a friend, you can call that friend at your free time. But the friend might not spare some time for you. Technologies like social networking sites solve that problem. If you have to talk to a friend for 5 minutes to share a piece of information, you can do that in less time on Facebook. Of 'coz it'll take longer time for them to respond, but on average, you are reaching out to more than one friend.

Second, there's an extra medium between you and the others. You have some type of controls over that medium. If anything goes wrong, you can control it to a certain extent. It gives a person a sense of control and reassurance, because no direct attack is there. Even if it's there, there's at least something you can do about it.

Last, you don't need to wait for something to happen. You can just leave a comment, post a thought on Facebook and just leave it there. Surprising, the amount of attention that you get from others on Facebook is higher than the amount of attention you get from talking to someone in person.

I don't like Facebook. I primarily had the account so that I could keep in touch with some friends. But I realized that I could try to do it in some other ways as well. If I have to have pictures or update my profiles constantly to get my friend's attentions, then I'm sure that I need better friends.

Wednesday, February 17, 2010

Simple Calculator Using Swing Part III

This is a continuation of a simple calculator program that makes use of swing. Just for recap, I covered a few topics such as how to add buttons to a panel, how to order the layout & how to add action listeners. This post will briefly explain of the logic of each action listener corresponding to each button in my calculator.

In my calculator, there're numbers 0 to 9 and other signs buttons. In this post, I will like to focus on how I develop my code regarding those arithmetic operation.

Each arithmetic operation consists of two operands, one operator and one result. Since we have only one text box, we definitely one temporary variable to store the number because the text box can hold only one number at one time. So, let's break down our process of adding numbers. It'll be like this :
1) Enter first number
2) Choose the type of operation
3) Enter second number
4) Choose = sign to get the result

As I mentioned, we need a temporary variable to store the first number, and we need to write a method to perform the arithmetic operation. So, after we enter the first number and choose an operation type, we need to clear out the first number so that when you enter a second number, the text box will start from scratch.

So, the code will look like this :
The above code is for addition. So, for other arithmetic operation, it'll be similar.
Now, what happens when you hit =. It's supposed to grab two numbers and return a result. And here's what the code looks like.
Of course, the whole project will consists of a bunch of if-else statement to capture the right button action. And note, since we're using a text box here, you can enter the numbers. However, you can't using any keys other than number keys to perform operation. Additional steps are required if we want to capture users' input from keyboards and that'll be one of my future topics.

Thursday, February 11, 2010

Hibernate & MySQL : Pitfall

As you know, I work with EJBs, Seam & Hibernate. I have nothing against them. In fact, I think the use of those technologies together with MVC architecture has many advantage in terms of development. First, we programmers do not have to worry about low level architecture. The use of Hibernate in object mapping to database actually eases out a lot of troubles of writing database calls. So, we can focus more on code development and efficiency. Or you can argue that programmers are generally lazy and always trying to find a way to make life easier. But sometimes, it can backfire.

Hibernate does a lot of things for us. As long as we know some hibernate annotations and a little bit hibernate sql, we can write an application with Java at business logic layer and any relevant database at back end. But here's one important thing before you develop your data model and start implementing. If you decide to use MySQL as your back-end database, MySQL doesn't allow you to join more than 61 tables at once.

Depending on what type of data model you have, it might affect you. For examples, we had object hierarchy data model with one root and multiple children. Since we rely Hibernate on querying the data from MySQL, Hibernate generates those queries automatically. If you have one parent with more than 61 child tables, hibernate will generate a query that joins all those child tables. You might be wondering how you can have a data model that has one parent and more than 61 child tables. Well.. you just can.. So, one way to avoid is not to use MySQL at all or try to have a better data model.

Thursday, February 4, 2010

Fundamental of Algorithms

I've started school again. So, between work and classes, I'm a bit busy. I'll occasionally write about some interesting problems/stories that I encounter at school. I am starting Master program in Information System at NYU. This semester, I'm taking Fundamental of Algorithms class.

Quite honestly, I was a bit worried of that class. I personally don't think I am a hardcore CS person. I love writing programs, solving problems and finding solutions. But I never really take interest in theoretical CS. Algorithms was a required class but I think I would have taken it had it not been required either. I am planning to make the best of my graduate studies(partly because it's a very very expensive investment) by taking as many classes that interests me, as I can.
My heart sank more after looking at the course website. It seemed like a really hard classes. Homework seemed to be like unsolvable puzzles because the professor mentioned that we're not required to solve it entirely.

But after two classes, I find myself enjoying the class. Yes, it's hard but it's totally worth it. I'm not sure which grade I will end up getting in the end. But I hope it is a good learning experience. And all I can now is try my best to learn and solve the problems.