04 November 2013

PrimeFaces 4 and Override IE Intranet Compatibility View Mode

We had the problem that since the migration to PrimeFaces 4 our JSF pages where displayed in IE compatibility view mode even though we specified the meta tag to control the IE mode:
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

The reason was that PrimeFaces puts the stylesheet links and the scripts right after the title tag.

After some research I found the solution on Stack Overflow:
http://stackoverflow.com/questions/14840259/ie9-rendering-ie8-document-standard

<h:head>
  <title>
    #{parameterBean.locationName} - #{parameterBean.version}   
  </title>
  <f:facet name="first">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  </f:facet>
  <link rel="shortcut icon" href="/proshop/psicon.ico" />
  <h:outputStylesheet name="style.css" library="css" />
  <h:outputScript name="calendar_locales.js" library="scripts" />
</h:head>

27 August 2013

Multiple MDBs with Durable Subscriptions on the Same Topic

In our scenario we have muliple JBoss servers that are connecting with a MDB to the same topic running on a central JBoss server with HornetQ.

First I tried to use MDBs with annotation based configuration. But this failed because I had to hard code the clientID and for every durable subscription the clientID must be unique.

To find the solution it took some time but it is quite simple. One has to use XML. There it is possible to use system properties. And because I didn't want to introduce a new system property I choosed an exisiting one: ${bind.address}

<message-driven>
  <ejb-name>CustomerUpdater</ejb-name>
  <ejb-class>com.prodega.proshop.integration.CustomerUpdater</ejb-class>
  <activation-config>
    <activation-config-property>
      <activation-config-property-name>
        destinationType
      </activation-config-property-name>
      <activation-config-property-value>
        javax.jms.Topic
      </activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
      <activation-config-property-name>
        destination
      </activation-config-property-name>
      <activation-config-property-value>
        /jms/CustomerTopic
      </activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
      <activation-config-property-name>
        subscriptionDurability
      </activation-config-property-name>
      <activation-config-property-value>
        Durable
      </activation-config-property-value>

    </activation-config-property>
    <activation-config-property>
      <activation-config-property-name>
        clientID
      </activation-config-property-name>
      <activation-config-property-value>
        ${bind.address}
      </activation-config-property-value>
    </activation-config-property>
  </activation-config>
</message-driven>

12 Juli 2013

Why I stopped using Scrum

In previous projects we used Scrum. I liked the daily stand up meeting and the planning process and I became a certified Scrum master.

But in the current project we do not use Scrum.

Why?
We have the perfect team size which is 3 (2 could be even better)!
Therefore we...

do no not need stand up meetings
And because we are only three people we don't need a daily stand up because we talk so much during the day we already know everything what is going on. Problems are solved when they come up during the day.

do not need a planing process
Planing and release process is very agile because we do both implementing new features and fixing problems of the running application. We also have kind of a back log which contains very fine grained tasks.
On the other hand because we are a very stable team with in deep know how of the whole application we are able to do reliable estimation continuously.

do not have sprints
We don't need sprints. Based on the current bugs/problems and the features we decide continuously when to release a new version.

Please don't get me wrong I don't "hate" Scrum but I think if your teams has the perfect size and is well performing it is not necessary to have a corset of a project development process.

There is also a worth reading article from Martin Fowler on XP: http://martinfowler.com/bliki/ExtremeProgramming.html


11 Juli 2013

Why I stopped using Maven

After 5 years with Maven I came to the conclusion that Maven is not very helpful with Java EE projects.

The reasons are the following:

Dependency Management of Maven is useless
With Java EE you have a target runtime (the application server). This runtime must be install anyway on every developers box for development and testing.
Now because you already have all libraries there (and in contrast to the Maven repo in the correct version) you don't need Maven to take the libraries from elsewhere. Therefore Mavens dependency management is useless. So if you use JBoss for example you can reference JBOSS_HOME which anyway points to your JBoss installation.

Now what about other libraries you may want to use in your project?
The solution is quite simple: Put them where they must be. Means in your EAR project in the lib folder or in the WEB-INF/lib folder in your WAR project! So you can put them into your version control system and you are sure everybody takes the same libraries.

Maven is not a good build tool
Ant in the past and Gradle nowadays are much more flexible and powerful build tools. They are simple and very customizable and will fit perfect what ever your build needs.


28 Mai 2013

I'm a Craftsman and not an Engineer

After 18 years of software development I'm convinced that software development is a craftsmanship and not an engineering discipline.

The reason is that software engineering is something you can learn at the university but to be a software craftsman you need a lot of practice and you need to get better everyday and learn from mistakes.

So I'm proud to be a craftsman!

11 Mai 2013

Migrating JTAF to JavaScript and REST

17 years ago I developed the first version of JTAF. Java Track And Field is an administration tool for track and field competitions. The Turnverein Erlach organizes every year a kids track and field competition and we have 2 to 3 CIS (Concours Intersection) also competitions for kids every year.

The first version of JTAF was an Excel app with VBA. After a few years JTAF was migrated to Access 2.0 and when I started the first Eclipse RCP application in 2005 at Swiss Railways I decided to do a complete redesign of JTAF using Eclipse RCP. See

JTAF is currently a single user application. All data is stored in an XML file. But if the competitions are growing we need multi user capabilities. Therefore I decided to do a compete redesign of JTAF.

I will use JavaScript/HTML5 on the client side and on the server side Java EE 6 with a REST interface that provides access to the date and consumes and produces JSON.

I think this architecture is the future architecture of all web based - and when we look at Windows 8 - also desktop based client applications.

If you like to see the progress of the development feel free to clone the Git repository: https://github.com/simasch/jtaf

If you have any suggestions or questions concerning the architecture please ask. 

Btw. I don't care about browser backward compatibility because I think that these days and also in the near future it is mandatory to use the newest browsers. I personally prefer Chrome because it implements the most HTML5 features. See: http://html5test.com/

I will post regularly about the progress of JTAF. Stay tuned!

29 April 2013

JHCR implements ROCA

I developed a small web app using JavaScript, HTML, CSS and REST. It's an implementation of ROCA style and I call it JHR: https://github.com/simasch/jhcr/

27 April 2013

Learning JavaScript and ROCA

Currently I'm learning JavaScript and HTML5. Why you may ask. Because I think that it is the only right way to create web applications.

For years I developed web applications with frameworks like JSP, Struts, JSF, PHP or ASP.NET. And all these frameworks are generating HTML code on the server.

With JSF you have a lot of component frameworks like PrimeFaces, RichFaces etc. hiding the JavaScript stuff behind a more or less simple programming model. But is that the way to do it?

I think no. If you want to create responsive web applications you must develop on the client side. And the client side means HTML and JavaScript.

When we look at Java EE or other server side frameworks we will find the perfect server interface for such applications: REST with JSON. So there is no need to do any conversion on the client side.

When I was think about my ideas and developing a sample application one of my colleagues pointed me on ROCA. And I completely agree with all recommendations! So have a look: http://roca-style.org/

09 April 2013

QLRM is available in Maven Central

<dependency>
  <groupId>ch.simas.qlrm</groupId>
  <artifactId>qlrm</artifactId>
  <version>1.0</version>
</dependency>

More information about QLRM

08 April 2013

SQL Result Mapper is now QLRM

Because the SQL Result Mapper can also map JPQL results I renamed it to QLRM - Query Language Result Mapper.

https://github.com/simasch/qlrm

22 März 2013

SQL Result Mapper 0.1.0 in Maven Central Repository

I just released version 0.1.0 of my and it is now available from Maven central repository.

More details on GitHub: https://github.com/simasch/sqlresultmapper

21 März 2013

Generate TOs from Query

My SQL result mapper has a new feature:


ResultSet rs = stmt.executeQuery("SELECT NAME FROM EMPLOYEE");
ClassGenerator.generateFromResultSet("", null, "EmployeeNameTO", false, rs);


The ClassGenerator will generate a TO from any SQL SELECT query.

Check it out:
https://github.com/simasch/sqlresultmapper

08 März 2013

SQL Result Mapper on GitHub

I published the SQL Result Mapper on GitHub:

https://github.com/simasch/sqlresultmapper

JpaSqlResultMapper instead of Constructor Expression

The previously mentioned JpaSqlResultMapper can also used as a replacement of the JPA Constructor Expression.

Example:
Query q = em.createQuery("SELECT c.id, c.type, c.euroExchangeRate FROM Closing c");
List<ClosingRecord> list = JpaSqlResultMapper.list(q, ClosingRecord.class);
The advantage of this approach is, that you don't have to worry when you are moving ClosingRecord to another package because the full qualified class name is not mentioned in the JPQL query.
So it's more refactoring friendly.

JDBC: Using POJOs in SQL Queries Result Mapping Simplyfied

... and because it worked so well with JPA I created a result mapper for JDBC:

public class JdbcSqlResultMapper {

  public static <T> List<T> list(ResultSet rs, Class<T> clazz) 
    throws SQLException {
    List<T> result = new ArrayList<T>();
    Constructor<?> ctor = 
      (Constructor<?>) clazz.getDeclaredConstructors()[0];
    while (rs.next()) {
      Object[] objs = 
        new Object[ctor.getParameterTypes().length];
      for (int i = 0; i < ctor.getParameterTypes().length; i++) {
        objs[i] = rs.getObject(i + 1);
      }
      createAndAddBean(ctor, objs, result);
    }
    return result;
}

  private static <T> void createAndAddBean(
    Constructor<?> ctor, Object[] args, List<T> result) {
    try {
      T obj = (T) ctor.newInstance(args);
      result.add(obj);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
}


JPA: Using POJOs in SQL Queries Result Mapping Simplyfied

Because there is no Constructor Expression for native SQL queries in JPA I wrote a simple SqlResultMapper. The result mapper is inspired by EclipseLink and Hibernate:

  • http://onpersistence.blogspot.ch/2010/07/eclipselink-jpa-native-constructor.html
  • http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querysql.html#d0e13904
In contrast to these two vendor specific implementations my JpaSqlResultMapper works with every JPA implementation.

There are two important remarks:
  1. Constructor must have the same number of arguments as the result of the SQL query
  2. The result types must match
Your comment is highly appreciated!

public class JpaSqlResultMapper {

  public static <T> List<T> list(Query q, Class<T> clazz) 
    throws IllegalArgumentException {

    Constructor<?> ctor = 
     (Constructor<?>) clazz.getDeclaredConstructors()[0];
    List<T> result = new ArrayList<T>();

    List<Object[]> list = q.getResultList();
    for (Object obj : list) {
        if (ctor.getParameterTypes().length == 1) {
          obj = new Object[] { obj };
        }
        createAndAddBean(ctor, (Object[]) obj, result);
      }
    }
    return result;
  }

  private static <T> void createAndAddBean(
    Constructor<?> ctor, Object[] args, List<T> result) {
    try {
      T obj = (T) ctor.newInstance(args);
      result.add(obj);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
}

17 Februar 2013

Next jug.ch Event in Bern

The next jug.ch Event in Bern will be about Ceylon, my favorite Java VM language:

http://www.jug.ch/html/events/2013/ceylon.html