JSF RI 1.2_x configuration parameters
The JSF 1.2_x reference implementation is using a couple of configuration parameters that are not easy to find. So I did a source code search and found them in the
com.sun.faces.config.WebConfiguration class.
eclipse the memory hog
Occasionally I have to help people with this painful java.lang.OutOfMemoryError: PermGen space because it is running out of PermGen space. Here I have found a good article explaining the necessary setting – in future I can just direct them to my posting and they can help themselfes
Whats coming up in Java SE 7
In the past I have been a bit lazy on staying up-to-date with latest JDK developments, at least last year I have been to JavaPolis 2006 and listened to some interesting talks of Sun engineers about the future of the Java platform and especially the language itself.
Development for Java SE7 is under full steam and as of writing this post installable previews of the JDK 7 Project are available. I have put together a list of the major enhancements (all driven by JSR communities) of the platform.
Modularity: JSR 294 specifies so called superpackages (there will be a new keyword superpackage). Now packages are more than a means for hierarchically organizing your classes. More semantics are added as it will be possible to put visibility attributes on packages.
JSR 277 defines new deployment mechanisms through deployment modules that will be packaged with a new distribution format (JAM Java Module). So in future a build process may also be called ‘JAM session’
If you want to bruh up your knowledge on this I recommend a presentation published at parleys.com.
Swing: rich client technologies have been pushed a lot in the last 2-3 years. The Java API for Rich Client development lacks support for typical development task (this is where the eclipse platform competes successfully and is unbeaten). So now the JSR 296 (Swing Application Framework), JSR 295 (Bean Binding Framework) and JSR 303 (Bean Validation Framework) try to fill some of the gaps. I haven’t had the time to look at JSR 295 but this looks similar to what JBoss is doing with Hibernate Validator ( see one of my previous posts).
Reified Generics: Weren’t we excited as we heard about Java5 would offer generics/type templating didn’t we get really disappointed when we experienced type erasure. Now it seems that type information will be made available at runtime for templated types. I had a few occasions where this would have been useful to me.
Short Instance Creation: Isn’t it a pain to type Map<String, Object> map=new HashMap<String, Object>(). With Java7 there will be relief and this could look like Map<String, Object> map=new HashMap().
Annotations on Java Types: Annotations will be supported for more syntax element (JSR 308).
Language-level XML: I’m a bit scared about this one. See Mark Reinholds talk at JavaPolis 2006.JavaBean Property Support: Groovy (like other scripting languages) has a very explicit notion of a property expressed by syntactical elements. In the future Java we might see new keywords and we no longer have to select Alt+Shift+S+Generate Setters and Getters… (using my favourite IDE eclipse).
Closures: If you have ever programmed Lisp or Smalltalk (yes I did this) you really miss passing around code as argument to method calls etc. Scripting languages have gained wide popularity due to their simple but expressive syntax – so there is pressure on the Java language to catch up with these.
invokedynamic: In order to better support scripting languages a new byte code instruction invokedynamic (JSR 292) will help that scripting languages will perform much better on the Java platform.
Date / Time API: Probably inspired by the Joda Time project we might see an improved API (JSR 310) for manipulating date and time types.
Units and Quantities: If you are in implementation of business applications you repeatedly have to come up with your own implementations of units, quantities, etc. JSR 275 will address this by considering to include the JScience project.
JMX: JSR 255 defines JMX 2.0 which will feature annotations and remote connectors based on web services
Javadoc: Seems Javadoc has come to age and needs some update (JSR 260).
NIO 2: JSR 203 is going to complete the NIO API that was introduced with Java5.
JSF life-cycle – the trap?
I’m doing quite a lot of JSF demos and prototypes for my consulting and coaching engagements. So (some months ago) I started with a simple framework to speed up things.
One of the classes in this mini-framework is providing a query-by-example style user interaction
- fill in a query form
- perform a query based on the query fields
- show a table with the query matches or show a form if a single row matched
For providing the query result I’m working with a DataModel that is implemented through a property model.
protected DataModel model = new ListDataModel(Collections.EMPTY_LIST);
@Override
public DataModel getModel() {
model.setWrappedData(service.queryByExample(example));
return model;
}
An instance of the class providing the property above is bound as a request scoped managed-bean. Everything is working fine, but as the JSF life-cycle allows a property to be read multiple times as the view is processed. In a simple GET request it would be called once only – during the RENDER_RESPONSE phase. In a post-back it would be called at least during APPLY_REQUEST_VALUES and RENDER_RESPONSE so the database would be hit at least twice.
As I further analyzed this it got clear that the first hit is not returning the right result as the query form attributes have not yet been applied to the bound managed bean properties (this would only happen after the UPDATE_MODEL_VALUES phase).
Only the second query execution returns the desired result.
So I was like this: why not suppress the first query make my database’s life not miserable. Using the beforePhase and afterPhase method binding of the
BUT now my command links for each row were not working anymore.
Hibernate Validator
I have been using Hibernate for quite a number of projects now mostly all of them with JSF for implementing the web interface. I’d always found it boring to do the “form validation thing” – mostly it is look at the constraints in the mapping definition and attach the proper validation tag to a form input element.
So today I had a look at the Hibernate Validator project that promises to make those validation constraints from the model available across all layers of application code. The project provides plenty of annotation types for annotating the domain classes. In general I try not to overuse annotations, especially those for mapping domain attributes to database entities – but this kind of annotations make sense to me!
As you would expect Hibernate Validations integrates with Hibernate core of course and JPA implementations so all of your annotated elements will be validated when persisted.
To perform application level validation a validation API is provided for validating bean instances or single bean properties.
ClassValidator validator = new ClassValidator(Car.class);
InvalidValue[] validationMessages = validator .getInvalidValues(porsche);
InvalidValue[] propertyMessages = validator .getInvalidValues(porsche, "engine");
Overall the API looks fairly slim and simple! In the next days I will investigate if the API allows “nested properties”. I’m thinking of creating some JSF tag (like the Seam tags) to perform validation of complete forms
Maven2 eclipse web tools platform integration
When developing web applications it’s always been a hassle to keep the WEB-INF/lib folder up to date especially when starting to experiment with different versions of libraries or frameworks .
In the past (since being a Maven2 user) I helped myself with issuing the mvn war:inplace command to pull in all required libraries into WEB-INF/lib. So, occasionally I only would update my POM and rerun the command to have the latest versions of jars in my project!
This is extremely handy when using profiles for example to switch dependencies between a set of JSF 1.1 or JSF 1.2 libraries. Only with a twinkle I could change the classpath definition for any project. Ok so far this is nice.
For server development I’m working with the WTP plugin which makes handling a server a bit easier. So, regarding my library dependencies I’d feel more comfortable if they were updated every time I started my server (and thus publish the latest project files to the server).
So, I updated my m2eclipse plugin to 0.0.11 and tried to mark the Maven Dependencies Library Container as a J2EE Dependency, restarted my Web Container and was really excited that finally this is supported now. This means all of my dependencies from pom.xml are actually deployed to the server.
The Power of Java5 Enums
A while ago I started my own initative to jump onto the Java5 train and use more and more features of the platform. In the past I had been forced by customers still using Java 1.4 to stick to it. I feel slowly now Java5 seems to drip in!
A few days ago I did some coaching on JSF and JPA and created a prototype to show to my trainee. I had the task of creating a JSf form that would allow to select from a select box a know set of values. On submission of the form each of the select box states should trigger a different action. Traditionally one would handle this with a stupid if then else if... cascade.
With Java5 enums this can be done much simpler and easier to extend (for additional states).
enum State {
A {
@Override
void doSomething(Disposition disposition) {
disposition.changeStateToA();
}
},
B {
@Override
void doSomething(Disposition disposition) {
disposition.changeStateToB();
}
},
C {
@Override
void doSomething(Disposition disposition) {
disposition.changeStateToC();
}
};
abstract void doSomething(Disposition disposition);
}
So this was the part of defining the possible states and the operations associated with each of the states. Now we need to convert the form input (from the select box), which is a simple string, into a enum.
State state = State.valueOf(formObject.getSelectBoxValue());
state.doSomething(formObject);
Pretty compact – isn’t it, and any time you need a new state you just add it to the enum type along with your operation. It is even possible to enumerate all of the enum states – the enum type provides a static method values() – to populate a select box in the user interface.
So when should you use enums? Any time you need a fixed set of constants. That includes natural enumerated types as well as other sets where you know all possible values at compile time, such as choices on a menu, rounding modes, command line flags, and the like. It is not necessary that the set of constants in an enum type stay fixed for all time. The feature was specifically designed to allow for binary compatible evolution of enum types.
NetBeans IDE 6.0 Milestone 10 (M10)
In the past NetBeans has been doing a good job in terms of catching up with the feature rich-ness of the eclipse platform. Currently I feel the eclipse platform does not offer enough support for plain JavaSE and Swing based rich client development, though there is excellent support for eclipse RCP stuff.
Previous releases of NetBeans have drawn attention through their GUI Builder Mantisse, the upcoming release of NetBeans IDE 6.0 will now extend this offering to rich client developers by adding more features:
- Swing Database Applications (JSR 295)
- Swing Application Framework (JSR 296)
Being a Java developer with focus on web applicationd development I felt that I also should try to keep any eye on rich clients as this topic is drawing more and more attention (it’s not all about AJAX).
So I will give it a try and checkout some of the features of NetBeans 6.0. In case that the included versions of the JSR 295 and JSR 296 implementations should proof usable I consider migrating my richclient demo application from spring-rcp (a project that does not seem to be very active in the past 6 months).
JavaServer Faces. The Complete Reference
A few days ago I received a book that I have been wating for a while: “JavaServer Faces. The Complete Reference”. It is covering both JSF 1.1 and JSF 1.2 and plenty of advanced techniques for getting the most out of JSF! After going over a few pages I soon got the impression that the book was a good choice. Many of the Tips regarding JSF 1.2 should help me to switch to JSF 1.2 as soon as possible.
Just an example: With JSF <= 1.1 there is always the issue with initializing managed beans especially reading data from some data source. You can’t do it in an accessor method (aka. getter method) as the JSF life-cycle does not guarantee that the method is only called once (actually it can be called multiple times in different phases of the life cycle). In this special situation with reading data from a data source you would hit the database multiple times and thus stress the database. So you always had to find ways to avoid this situation. There are some solutions out that can help with this issue.
With JSF 1.2 this has been adressed by adding the beforePhase and the afterPhase attributes to the f:view tag.
JavaPolis 2006 DVD set arrived
A few days ago I finally received the DVD set for the JavaPolis 2006 one of the coolest Java conferences.
It’s one of the conferences with the highest return on invest. High quality sessions with renown speakers and crowd from all over the world. And the best they publish some of their talks as synched video + slides online at Parleys and on top of that you can buy all of the talks on DVD.
See you there again for JavaPolis 2007.

