Un Tutoriel Simple de JSF avec PrimeFaces et le Traitement des objets JSON en Java

The following tutorial is an example of parsing JSON objects and displaying them on a web page using JSF 2.1 and PrimeFaces 2.2 which is a rich-component framework for JSF adding AJAX and Web 2.0 capabilities to your web application.

What you need for this tutorial

Oracle JDK 1.6 or later
Netbeans 7.0 or later

The following tutorial is an example of parsing JSON objects and displaying them on a web page using JSF 2.1 and PrimeFaces 2.2 which is a rich-component framework for JSF adding AJAX and Web 2.0 capabilities to your web application.

What you need for this tutorial

Oracle JDK 1.6 or later
Netbeans 7.0 or later

[adsenseyu1]

Bu yazımda döviz kurları bilgi akışı içeren bir JSON nesnesini işleyip, bir web sayfası üzerinde JSF 2.1 framework’ü ve JSF için bir zengin bileşen kütüphanesi olan PrimeFaces 2.2 kullanarak AJAX ve Web 2.0 özellikleri ile nasıl görünteleyebileceğimizi göreceğiz.

Bu öğretiyi uygulamak için nelere ihtiyacınız var

  • Oracle JDK 1.6 veya sonraki bir sürümü
  • Netbeans 7.0 veya daha yeni bir sürümü (farklı bir editör ve geliştirme ortamı kullanmayı tercih ederseniz, Gerekli kütüphane ve bileşenlerin tümünü manuel olarak projeye dahil etmeniz gerekebilir. Bkz. sonraki bölüm)
  • Tomcat 7

Kullanılan teknoloji ve kütüphaneler

  • JSF 2.1 (Mojarra 2 kütüphaneleri yani jsf-api.jar, jsf-impl.jar, jstl.jar ve standard.jar)
  • PrimeFaces 2.2.1
  • JSON (Java için)
  • commons-logging-1.1.1.jar
  • log4j-1.2.16.jar
  • httpcore-4.1.4.jar
  • httpclient-4.1.3.jar

Projeyi JSF 2 ve PrimeFaces desteği dahil olacak şekilde hazırlama

Netbeans’i açın ve aşağıdaki adımları sırayla izleyin:

13 réflexions au sujet de « Un Tutoriel Simple de JSF avec PrimeFaces et le Traitement des objets JSON en Java »

    • A Managed Bean is instantiated as soon as a JSF action references a method contained in it, in the case of the ExchangeRatesBean, it’s invoked as index.xhtml is called in the browser.

    • Sure. The main strategy here is pulling the exchange rate data once and providing that very data to all visitors (until someone invokes the Refresh action, which will benefit every new visitor) as there’s a very very little chance that there would be dramatic changes in the rates. You could change to scope of the managed bean to « session » (i.e. @SessionScoped) or even lower the scope as low as to the « request » (@RequestScoped) but I didn’t want to add extra load to the service (data) provider for a free service and therefore chose to avoid pissing them off.

  1. Primefaces action commands does not function on cloudbees, though it is all wirk on local machine with the same server version. What could cause to this?

  2. Change this code:

    into:

    @PostConstruct is automatically called when the bean gets initiated, so you shouldn’t call that method yourself.

    • @Serkan,

      Thanks for your comment. My current WordPress configuration seems to have stripped some of your <code> suggestion, but

      since

       <p:commandButton id ="ref" value="Refresh" ajax="true" action="#{exchangeRatesBean.kurlariYukle}" ... 

      invokes the method

      kurlariYukle()

      for refreshing the exchange rates, and I didn’t want to use extra space for this example, I simply put @PostConstruct above it to have this method called automatically once the bean is initiated.

      But yes, a good practice in a real life application could have been separating this logic elsewhere and a shorter @PostConstruct method to call the method from wherever it is positioned.

      Note: Please use the pre tag instead of <code if you wish to comment further and submit a <code suggestion.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

*