Friday, November 11, 2011

Chrome is not an option

I had the chance to see a Google user experience questionnaire. One of the questions was "Which web browsing software do you use"?



Apparently, Chrome is not an option!

Friday, August 26, 2011

Richfaces CDK Tutorial - "Hello, World!"

I like the JBoss technology stack. The power of the technology is important factor, but sometime the well documented products are giving the competitive edge.

JBoss provide a powerful JSF component development kit (CDK), along their JSF component library (Richfaces), but in oppose to most of their products (such as the AS, Seam, Weld, Richfaces), Richfaces CDK is lacking of a clear documentation. Especially when talking about booting up a new tag library. I haven't found much resources in the net as well, so I decided to write a clear walk-through for using it, for a better web out there.

For those who are impenitent, you can download the working sample immediately from Github at https://github.com/yonatang/cdk/tree/hello-world.

Lets start!

First, you'll need to create a Maven project. CDK project must be a Maven project, since it automatically generate code for you by a Maven plugin.
I created a parent project, which holds two modules - the tag library and a WAR project to demonstrate it.
Your directory tree should look like:
cdk
|
+-- tags
|
`-- example

cdk/pom.xml

The parent ("cdk") pom.xml should just hold the dependency and repository declarations. It should configure the CDK plugin (which will generate lots of code for you later on).



cdk/tags/pom.xml

Next, we'll need to define the tags pom.xml. Mind that only here we are actually using the CDK Maven plugin (while in the parent pom we only set the way we are going to use it). We'll need the CDK annotation JAR, the JSF API and JavaEE web API jar. That's all (for our simple hello world, at least):



cdk/example/pom.xml

And last, we'll need a project to show our wonderful tag we'll produce. I'm deploying it into a JBoss AS 7, which is a JavaEE capable, so no other dependencies (such as JSF libraries) are required. If you're using thinner containers, you should add the needed dependencies to run a JSF application. I added the Maven deploy plugin to deploy the WAR into a JBoss AS 7. You can omit it, if you like.



cdk/example/src/main/webapp/WEB-INF/web.xml

Our WAR project wouldn't work without the web.xml, located at src/main/webapp/WEB-INF: (nothing fancy, just a standard JSF servlet declaration)



cdk/example/src/main/webapp/WEB-INF/faces-config.xml

And we'll need a faces-config.xml file at /src/main/webapp/WEB-INF in order to declare its a JSF application. Since we're using JSF 2, we won't need anything declared in it:




cdk/example/src/main/webapp/index.xhtml

Let's put two more files, the index.xhtml and index.jsp files, just to display our tag:



cdk/example/src/main/webapp/index.jsp

A simple redirection to the index.jsf file.



Ok. We've done with the setups. Now lets create a tag! We will create 3 files, which will be used by the CDK plugin to generate the rest of the code: package-info.java, AbstractHelloWorld.java and HelloWorldRenderer.java

cdk/tags/src/main/java/.../package-info.java

This file just declare the URI namespace and the package namespace for the plugin. You can read the file as an instruction to use the xmlns "http://yonatan.me/cdk", with a short name of "cdk", for all the annotated classes under the "me.yonatan.tags package". Those definitions will be placed at the taglib.xml file, which will be automatically generated for you.



cdk/tags/src/main/java/.../AbstractHelloWorld.java

This is an abstract class that extends the standard JSF UIComponentBase class. The CDK plugin will generate another class that will extend it, and implement automatically whatever needs to be implemented. You can think about this file as the interface of the tag. We'll define there its attributes, its tag name, and which class will render it.
Since our sample here is trivial, the class almost doesn't have any information or logic. In the next posts I'll show more complex usage of it.



cdk/tags/src/main/java/.../HelloWorldRenderer.java

The last file, which extends the JSF standard Renderer class. If AbstractHelloWorld was the interface, this is the implementation. This will produce the actual HTML/JavaScript that will produce our tag (in our case, a simple DIV element with "hello, world!" in it).



Well, that's it. Run you Jboss 7, Compile the project with mvn clean package, and go to http://localhost:8080/cdk-example/index.jsf. If you've done everything right (or just download the project from github), you'll see our little "hello, world!" message.

A glance in the project itself, under /target directory of the tags project will reveal generated code: another .java file named UIHelloWorld was created, and the .xml files cdk.taglib.xml and faces-config.xml were generated too during compilation. A quite peek in them will show you that lots of boilerplate code that was saved from you to write (and even more important, to maintain!)

Next time, we'll add more functionality to our component, using nifty JavaScript libraries.

Links:
The code - https://github.com/yonatang/cdk/tree/hello-world
Community documentation for CDK 4 - https://docs.google.com/View...
JBoss how-to in their wiki - http://community.jboss.org/wiki/HowToCreateJSFComponent

Saturday, June 11, 2011

What is the connection between Facebook and Pornhub?

Google has announced recently a lab called "Google Correlate", which is one of the coolest ever (IMHO).

Basically, it allow you to search for the most correlated queries - for example, the trend of searching the term "Facebook", has a 0.9934 correlation (1 = perfect correlation, 0 = completely independent, -1 = the perfect opposite) for the trend of "Pornhub". Interesting.

Another cool feature is to draw a trend graph, and see what are the most matching queries for that trend. For example, the best match for the trend:
is "2008 news" (which makes a perfect sense - at 2007 people wouldn't search for 2008 news, and at 2009 people wouldn't be interested in 2008 news).


So, all the statistical geeks out there, go ahead play with it!

Tuesday, May 31, 2011

Installing Chrome offline

After the recent unfortunate incident that happened in RSA, several extra security steps were taken. Among them, some of our machines were physically disconnected from the Internet.

But, we would still needed to use those machines for our day-to-day engineering tasks, which include using some Intranet applications (such as a CI software, Maven repositories, Sonar reports, etc.). Using IE is out of the question for me, and I want to have a choose between FF and Chrome.

Installing FF was easy - just to download and install the FF installer (here). Chrome was a bit more difficult, since the normal installation flow downloads a small (~500k) downloader, which downloads the rest of Chrome during installation - which is obviously impossible on my machine.

I found a standalone installer for Chrome (here), but running it caused the installer to stuck on "Initializing..." phase of the installer. Quick investigation using Wireshark discovered that the installer is trying to verify if a new version exists at tools.google.com. So, adding the following line:

127.0.0.1 tools.google.com

to the hosts file (located at c:\windows\system32\drivers\etc\hosts on Windows machine, /etc/hosts on Linux), which effectively blocks that site, solved the issue. Now I'm able to use both Chrome and FF on my computer again.

Please note that the hosts step shouldn't be done on an internet enabled machines, since it might cause several Google tools to stop function properly. On an internet disabled machines (such as mine), that site is blocked anyhow, so it won't affect any software more than the main blockage.

Monday, April 25, 2011

@Inject inside Servlet Filter

I wanted to apply the Namespace pattern that is suggested in the Google App Engine documentation, with a CDI application (Weld implementation of JSR-299).

Since I wanted to user to choose an application during login, I needed to keep the namespace at a session bean. Since GAE is not an EE container (yet...), rather than a servlet container, I needed a different mechanizm to inject beans. I found this piece of code which came real helpful at DominikDorn.com, and created the following GaeCdiFilter abstract class:


During init(), the following abstract class get a BeanManager instance from the Servlet Context. Then it scans itself during init(), and instancing by injection each field that is annotated with @Inject.

@PostConstruct and @PreDestroy are not supported here, but it can be easily implemented as well. To use it - just extend GaeCdiFilter. If you need to override init(), don't forget to call its super (otherwise the whole thing won't work!)

Wednesday, April 13, 2011

Gson 1.7 is out, but...

Google has announced Gson 1.7 library is out few hours ago (Gson is a Java library to convert JSON to Java objects and vice-versa).

But, seems the wrong jar was uploaded into maven central repository - downloading com.google.code.gson:gson:1.7 yields the javadoc file, instead of the library itself.

I've created a issue report in the code site, and I hope this would get fixed soon enough.


File size is the same:

SHA1 for jar file:

SHA1 for javadoc file:


Monday, March 28, 2011

Richfaces 4.0.0.Final is out there!

For some reason, the guys at Jboss didn't release an announcement, but since March 19, 2011 (8:11 AM EDT) Richfaces 4.0.0.Final is available to download from jboss maven repository.

So, you can start your Richfaces 4.0.0.Final project right now, using the following maven declartion:


Happy coding!

Sunday, February 6, 2011

Eclipse "Open in Explorer" plugin

Ever required to view a folder from the explorer window, and not from Eclipse? Ever needed to change multiple files' read-only attribute?
Well, ExploreFS plugin for Eclipse (http://junginger.biz/eclipse/) might suite you. Plus, it comes with RSS reader and graphical memory usage graph view.