Tuesday, July 28, 2009

Tapestry 5.1 on JBoss 5.1

Well, today I tried this configuration and guess what... it didn't work! We all know who to blame (and this is not the Tapestry guys)! Now, what can we do about it?

The information on Tapestry wiki states that there is a workaround required for Tapestry to work on JBoss 5.0.x. The wiki says also that the workaround wouldn't work with JBoss 5.1. Hmmm... to bad, but why wouldn't it work?

I've decided to debug the code I got from the wiki and take a look at the behavior differences on both versions of JBoss. After an hour of debugging I found out that the URLs to the resources are build differently for jars which are packed inside of wars. There is however easy way to make them look the same.

Here's my patch for the original workaround at Tapestry Wiki.


...
public URL convert(URL url) {
if (url != null && url.getProtocol().startsWith("vfs")) {
// supports virtual filesystem used by JBoss 5.x
try {
URLConnection connection = url.openConnection();
Object virtualFile = invokerGetter(connection, "getContent");
Object zipEntryHandler = invokerGetter(virtualFile, "getHandler");
Object realUrl = invokerGetter(zipEntryHandler, "getRealURL");

// start of the patch (small fix for JBoss 5.1)
if (realUrl.toString().endsWith("jar")) {
Object localPath = invokerGetter(zipEntryHandler, "getLocalPathName");
Object context = invokerGetter(zipEntryHandler, "getZipEntryContext");
Object tempUrl = invokerGetter(context, "getRealURL");
realUrl = new URL(tempUrl + "" + localPath);
}
// end of the patch
return (URL) realUrl;
} catch (Exception e) {
log.info(e.getCause());
}
}
return url;
}
...


Now, you may enjoy having Tapestry on your favorite application server... and wait for a more professional workaround from Apache guys.

Twitter - isn't it just an observer pattern

It just occurred to me how great and powerful design patterns really are. Well, I must admit that I always thought about them as if there were just a tool that I can use to build great, exciting, flexible and maintainable applications. Well, after all that's totally true! However, it never occurred to me that I could take a design pattern and make an entire application out of it. Yes, I mean it! The pattern may be a great business idea! The business idea where the pattern implementation itself is all the software has to offer to its users. Sounds simple, doesn't it?

The concrete pattern that I am "secretly" thinking about is commonly known as an "Observer pattern". This "recipe" is extremely important to every good software developer who would like to build a flexible system which needs to deal with some sort of event handling… but you already know that. Now, take this pattern and map it to the real world. This is actually where it originally came from. What do you see?

I see e.g.:

  • newspaper companies and their subscribers

  • church and all the people who "subscribed" to it. They (typically) receive recent information about some sort of catholic events... etc. whatever...

  • the company which employs you and yourself. Well, you subscribed to get the money every month from them. The bad part is that you have to work to keep yourself on the list of subscribers.


As you can see our live is surrounded with observer pattern. It is natural that people love patterns. They make our lives easier. We don't have to think so much about that many things around us. Just this simple fact proves that a pattern itself can be a great business idea! How can we use it then to build our own business on the web using this common "routine"?

In my opinion, the best example is the Twitter. In Twitter you are acting as a Subject and Observer at the same time. The network of observers and subjects is therefore huge! Every time you post a message, all people who are your observers get informed about it. Every time the subject you subscribed to is posting an update you get informed about it too. Isn't it great!? Take a pattern and use it directly to make a lot of money. This is of course pure theory. The internal implementation of Twitter is probably not that simple, but this is not the point of this post.

So, when thinking about your next genius, innovative business idea, just make sure to take a closer look at the design patterns. Try to map them to the real world problems and use to build solutions nobody thought about yet.

I think that this approach will always lead you to a success. Here's why:

  1. This new thing of yours (whatever it is) will work for sure. Design patterns were tested by millions and proved to work correctly and efficiently.

  2. It will also be simple... and since people like it to be simple it makes a perfect match.

  3. We all probably will know this routine by our hearts. We just didn't suppose that you could use it this way. This means that the users will know how to use your software right away!

  4. There is more... and more... and more... but I am too lazy and too dumb to put them here.


Anyway, I will re-read my patterns book and look for some clues there.

Tuesday, July 21, 2009

Modern Web Design

If you are a guy who spends a lot of time on web application development, then check this out and tell me if you agree:

http://tapestryjava.blogspot.com/2008/06/time-breakdown-of-modern-web-design.html

Now.. this is so true, isn't it!

Monday, July 20, 2009

Do you own PT AX100 E/U?

For some time now, the device (which I personally love) kept misbehaving. Every 5min it turned itself of... very, very annoying when you watch e.g. an action movie.

If you too have this problem, this is what you should do to fix it:
http://www.youtube.com/watch?v=6jGwB05_gdk

Friday, July 17, 2009

Gmail-like text overflow

Today I've learned how to implement a nice gmail effect of text overflow. I was trying to build it for few hours with no good effect. I googled a bit and found the "correct" answer on this blog:

http://ajaxian.com/archives/learning-from-gmail

It's a very useful feature if you like to implement your web UI using liquid layout. The user may see more if he has a bigger screen (which is fine.. I like to know that having a big screen is actually a plus when I browse the net). Also, the effect allows your table to look more consistent independently on the screen resolution of the client viewing it. That's really nice!

Here's the style that I used:

...

.grid {
table-layout: fixed;
width: 100%;
}
.grid * td {
white-space: nowrap;
empty-cells: show;
overflow: hidden;
}

...

<table class="grid">
<col style="width:100px"/>
<col />
<col style="width:100px"/>
<tbody>
<tr>
<td style="padding-left:10px;">Other</td>
<td>
<a href="#">
Very long text.
</a>
</td>
<td style="padding-left:10px;">Other</td>
</tr>
</tbody>
</table>

...


And here's how it looks like:



I've dropped the "width:100%" property. It seems to be not necessary. Have a happy coding!

Tuesday, July 14, 2009

Impressed by Groovy and Grails

For the last few days I've been playing around with Grails framework just to get to know what it is about. I must say that I am really... no, that's to small for it... extremely impressed by its completeness, maturity and ease of use.

Building web applications is not an easy task. It involves many different subjects such as architectural deign, build process design and automation, database integration, user interface design, security, more and more stuff, etc. Grails covers all of those subjects within one, easy to understand framework. This stuff is really amazing!

Till now, I have been thinking that the only right technology for building web applications is Java. Well, I still think so, but now I would additionaly say... yes, it's Java but extended by Grails framework.

I really recommend you to take a look at the Apress'es book "The Definitive Guide to Grails 2nd Edition (2009)". Read a few chapters and discover what it means to quickly build complex web apps with an Agile framework.



Here's amazon link: The Definitive Guide to Grails 2nd Edition

Saturday, July 11, 2009

... } finally { certified = true; }

Yeah, I finally got certified!

It has been one of my TODOs for a few years now. The problem always was that I could never find time to prepare myself really well for this. There was this huge book to read, mock tests to do, etc. and lots of other task apart from that. I am happy that I didn't forget and finaly did what I planned to do.

I scored 84% and must say that I am pretty happy about it. Anything above 95% would probably mean that I am not a human beeing anymore but a Java compiler instead.

Some of the questinos were extremely hard but there were also no-brainers. Anyway, if you think that you could pass the SCJP exam without any preparation (because you have multiple years of expierience with Java) then you are totaly wrong! I screwed up mostly "Concurrency" questions even though I scored above 90% with Whizlabs Mock tests. It's just not predictable what kind of problems you may get to solve on the exam.

Now I may learn Groovy in piece :-)

Thursday, July 9, 2009

What's it gonna be?

Finally, THE TEST!

If everything goes well, I will get certified tommorow. After writing tons of code samples, reading the book, practicing with Mock test I am still not sure what's it gonna be!

Today I've learned something new! Would you expect something like this could print "true"?

Integer i = 18;
Integer j = 18;
System.out.println(i == j);


Interetingly, all samples shown below will print "false":

Integer i = 18;
Integer j = new Integer(18);
System.out.println(i == j);

...

Integer i = 128;
Integer j = 128;
System.out.println(i == j);

...

Integer i = new Integer(18);
Integer j = new Integer(18);
System.out.println(i == j);


Eeeh? Yes! Try it yourself! I'm not kidding! And there is more examples similar to the one shown above (e.g. Double.NaN == Double.NaN ... returns false).

Well, it's gonna be tough, that's for sure!

Wish me luck!