Tuesday, October 6, 2009

Preparing Glassfish V2 for JSF 2.0

I'm planning to migrate the web client of a JEE application from Apache Struts to JSF in order to reduce the complexity of the implementation and the number of required libraries. These libraries make the distribution package (ear) a giant file of 10MB, too much for a web application. :P However, since I don't like JSF version 1.2 because of several design issues, I decided to wait a bit more for a stable release of JSF 2.0. I think I'm waiting too much :(. The first time I saw a presentation about JSF 2.0 was in December 2008, during the last edition of JavaPolis (now Devoxx), and since that time I haven't seen any application server in its production release already available for this last JSF version.

Then I decided to make a little search on Google and I could find that JSF 2.0 RC can be configured to run on Glassfish V2/.1 without any complex step. Following the instructions of this page, I performed the following steps:
  1. download the Mojarra 2.0.0 RC binary bundle from this webpage;
  2. backup your existing jsf-impl.jar found in GF_HOME/lib;
  3. copy the new jsf-api.jar and jsf-impl.jar to GF_HOME/lib;
  4. edit your GF_HOME/domains/[domain-name]/config/domain.xml and add (or update the existing classpath-prefix) 'classpath-prefix="${com.sun.aas.installRoot}/lib/jsf-api.jar" to the tag;
  5. restart your server.
On your domain configuration file, domain.xml, set the classpath-prefix parameter as the example below:

<java-config
classpath-prefix="${com.sun.aas.installRoot}/lib/jsf-api.jar"
classpath-suffix="" ... >
...
...
</java-config>

Probably, you won't find the classpath-prefix parameter there, so there is no problem if you add it. ;) To check whether it is running correctly, open the Glassfish Admin Console (http://localhost:4848/), which is a JSF application, and see if it is running normally. The following line will be printed on the application server log file (server.log) when starting the JSF application:

Initializing Mojarra 2.0.0 (RC b16) for context ''

That's all! I'm not sure if it is enough. I'm going to start the migration in the next days. If I find issues during the process, I will come here to report them in details. I just hope that, when I finish this implementation, the market will finally offer an application server supporting JSF 2.0 by default.

8 comments:

  1. Hidelberto você saberia dizer se na data corrente que faço este comentário a temos alguma versão estável do JSF 2.0?
    ReplyDelete
  2. Sim. A boa notícia é que o JSF 2.0 já está em sua versão final, totalmente funcional em relação a especificação, estável e disponível para download no endereço: https://javaserverfaces.dev.java.net. Feliz ano novo!
    ReplyDelete
  3. Olá Hildeberto,
    Fiz os passos como sugerido no post e até ta funcionando, mas o css do jsf não está sendo carregado. Aparece somente os elementos sem formatação alguma.
    Sabe se tem como resolver isso? Se sim, como?
    Collins - Sefaz/pi
    ReplyDelete
  4. Olá, provavelmente a referência para o css no seu jsf não está apontando para o local correto do arquivo. Você está usando jsf puro ou facelets? Como está a linha onde você referencia o css e onde está localizado o arquivo na pasta web? As vezes uma "/" no começo do path pode ser a solução.
    ReplyDelete
  5. oi Hildeberto,
    Dá uma olhada neste link http://collinsnash.wordpress.com/2010/09/03/olha-ae-hildeberto/

    Postei pra ficar mais fácil de mostrar. Fiz um código bem simples pra testar mas o resultado não está "normal". Veja, por exemplo, que não aparece o panel, colocado no código.
    Collins - Sefaz/PI
    ReplyDelete
  6. Olá,

    vi lá o código e percebi que está faltando a referência para o css no código. Você precisa colocar dentro do < h:head > a referência para o arquivo, por exemplo:

    < link href="/[app]/resources/css/default.css" rel="stylesheet" type="text/css" / >
    ReplyDelete
  7. ... você também precisa colocar as classes do css nas tags que precisam ser estilizadas.
    ReplyDelete
  8. Oi Hildeberto,
    O problema na verdade era outro.
    Uso o netbeans e o mesmo gera o arquivo web-fragment.xml com a declaração da servlet do primefaces, quando o mesmo é utilizado (meu caso). Porém, preciso incluir esta mesma declaração no web.xml.
    Feito isso o projeto é executado normalmente e o css do prime funciona normalmente. Era esse css que não mostrava antes.
    Valeu!
    ReplyDelete