 |
Felipe Leme's Blog
Felipe Leme has worked professionally with Java since 1996, and in the last years had became an active enthusiastic of the technology: he is
a frequent speaker in the main Brazilian Java conferences, presented at JavaOne for 3 years in a row, is a developer of a few Java-based open-source projects (like DbUnit and Jakarta Cactus), and is an
individual member of the Java Community Process, where he took part of the JSP 2.1 and Java EE 5.0 expert groups.
He is a father of two, and in his spare time likes to assemble jigsaw puzzles and collect Marvel comic books with his older son, Thomas. He used to scuba dive as well, but have not dove yet in this new millennium.
Currently, he works as an independent consultant and Java instructor in Brazil, but is planning to move back to the US, where he worked from 1999 to 2002.
javafx is up and ^H^H^H^H^H^Hrunning
Posted by felipeal on December 04, 2008 at 09:55 AM | Permalink
| Comments (3)
With all this fuzz about JavaFX (which I've never cared for so far, and always thought it was something related to the FX TV channel), I decided to check the website. But to my surprise (or not!), all I got was a lousy "Your Application Server is now running" message, as you can see on this screenshot
Ironically, another post says:
You might want to go directly over the the JavaFX website to download the JavaFX SDK, but if you work in NetBeans 6.5 you don't have to bother.
Yep, you might want to go, but there is nothing there...
Final note/disclaimer: yes, this is a trolling blog. But I couldn't resist - almost 2 years in the making and the web server can't handle it? It reminds me that IBM ad about the Cheddar city website.
Adding EL support on your projects
Posted by felipeal on October 26, 2008 at 11:07 PM | Permalink
| Comments (10)
A few years ago, JSTL introduced the concept of EL (Expression Language) to the Java standards. Since then, the technology have been slowing climbing the JCP ladder, first becoming part of JSP 2.0, then having its own API (javax.el).
Although there is a lot of documentation out there on how to use EL in places that support it (like the aforementioned JSTL and JSP technologies), there is a lack of resources on how to support EL on *your* application.
First of all, why would you want to use EL on your application? Well, there is a couple of use cases. Basically, if you need some templating in your application, you could use EL (sure, you could use other projects like Velocity or even OGNL, but that's not the point). I used it myself in 4 opportunities: in a mailing application I worked on a few years ago, in the test cases of a project, in a project that generate alerts from templates, and in the upcoming JUnit in Action 2nd edition. As the first three cases are kind of private, let's use the book example as our use case scenario.
Chapter 17 of the book is about DbUnit, and one of the topics uses EL on DbUnit datasets. Roughly speaking, you could have an XML file like:
<?xml version="1.0"?>
<dataset>
<users id="${id}" username="ElDuderino" first_name="Jeffrey" last_name="Lebowsky" />
</dataset>
And then the EL engine would replace ${id} by the proper value.
Even though I like this trick (and I think it should be adopted by other prjects, like Unitils) and explained its benefits in that chapter, it was out of the scope of book to detail how it was implemented. And to my surprise, nothing in this area seems to be available elsewhere (it took me a lot of hacking back in 2006 to implement it for the first time, but I thought that by now there would be more tutorials on the subject).
Programatically speaking, you would like something like this:
String elText = "Dude, where is my ${car}?";
SomeSortOfContext context = new SomeSortOfContext();
context.bind( "car", "EL tutorial" );
String convertedText = doSomeMagic( context, elText );
// convertedText is "Dude, where is my EL tutorial?"
Anyway, without further ado, here is my quick howto (which is not necessarily the right approach, but it's better than nothing :-):
- First, get the el-api.jar. Where? Another of life's obscure mysteries, but long story short, try https://maven-repository.dev.java.net/repository/javax.el/jars
- Then you need to define SomeContext. The EL API defines an ELContext (javax.el.ELContext), but that is an abstract class - you need to extend it and implement the getELResolver(), getFunctionMapper(), and getVariableMapper() methods.
- For getELResolver(), you can just return a new BeanELResolver() (that class is part of the EL api). Similarly, you are not interested on getFunctionMapper() (unless you need to support EL functions), so you can create an inner class implementation that does nothing (don't panic, I will show the whole code below).
- Now comes the first real trick, implementing getVariableMapper(). For this dude, you also create your own implementation, which simply uses a Map to store the variables you want to bind. And as a courtesy to your fellow programmers, you add the bind() method shown in the above example.
- Next step is to get a javax.el.ExpressionFactory implementation. If you guessed that el-api.jar does not provide any implementation, congratulations, you read my mind! But in this case you don't need to create your own, you can get an existing implementation, such as Tomcat's (again, the shorcut is to download jasper-el.jar from http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/tomcat/jasper-el/6.0.18/)
- That leave us with the final step, the doSomeMagic() method, which is simply return factory.createValueExpression(context, elText, Object.class ).getValue(context);!
Confused? Welcome to the club :-).
Jokes aside, the test case below contains the whole code:
Continue Reading...
 |
 |
December 2008
| Sun |
Mon |
Tue |
Wed |
Thu |
Fri |
Sat |
| |
1 |
2 |
3 |
4 |
5 |
6 |
| 7 |
8 |
9 |
10 |
11 |
12 |
13 |
| 14 |
15 |
16 |
17 |
18 |
19 |
20 |
| 21 |
22 |
23 |
24 |
25 |
26 |
27 |
| 28 |
29 |
30 |
31 |
|
|
|
Search this blog:
Categories
Business
Community
Community: Java Enterprise
Community: Java Specification Requests
Community: Java Tools
Community: JavaDesktop
Community: Mac Java Community
Deployment
Distributed
Eclipse
J2EE
J2SE
JavaOne
Linux
Open Source
Performance
Tools
Web Applications
Archives
December 2008
October 2008
June 2008
March 2008
July 2007
June 2007
May 2007
February 2007
November 2006
July 2006
June 2006
March 2006
June 2005
January 2005
December 2004
October 2004
July 2004
March 2004
January 2004
November 2003
October 2003
September 2003
Recent Entries
javafx is up and ^H^H^H^H^H^Hrunning
Adding EL support on your projects
Configuring Eclipse TPTP (a.k.a PQP) profiler on Linux
Articles
Creating EL-Aware Taglibs Using XDoclet
Passing dynamic values to taglibs via the JSP expression language (EL) is convenient, but is hard on the taglib developer and is therefore little-supported. Felipe Leme shows how code generation might solve that problem. Jun. 18, 2004 Validating Custom Tags at Translation Time
While typical JSP taglibs are held to a set of well known rules, many developers aren't aware that new rules can be defined and enforced by the developer. Felipe Leme examines these underappreciated JSP features. Feb. 4, 2004
All articles by Felipe Leme »

|