27 Mayıs 2008 Salı

JSF Web/Portlet Uygulamaları için JasperReports tabanlı Raporlama Java Kütüphanesi


JRRaporlama Java Kütüphanesi kaynak kodları:




JRRaporlama.jar dosyası:


 
Yukarıdaki JRRaporlama kütüphanesi hemen indirip JSF Web uygulamaları veya JSF portletleriniz içerisinde kullanarak 
HTML, PDF, Excel, Word gibi formatlarda Web veya portlet uygulamanız içersinde aşağıdaki gibi gösterebilirsiniz.  
 
 
RaporOlustur metodu:
public java.lang.String RaporOlustur(javax.faces.context.FacesContext fc,
                                     int raporTuru,
                                     java.lang.String dBDriver,
                                     java.lang.String dBConnectString,
                                     java.lang.String dBUserName,
                                     java.lang.String dBUserPassword,
                                     java.lang.String reportFileName,
                                     java.lang.String ReportFolderPath,
                                     java.lang.Object[][] parameters)


RaporOlustur metodu IReport ile olusturulmus olan rapor dosyasini kullanarak istenilen formatta rapor alabilmeyi saglar. Bu metod kendi Web uygulamaniz icerisinde kullanilir.

Alabileceginiz rapor formatlari PDF, Word/RTF, Excel ve Html'dir.

Html biciminde rapor istiyorsaniz kendi Web uygulamanizin web.xml dosyasina asagidaki kismi ekleyiniz.

<servlet>
<servlet-name>ImageServlet</servlet-name>
<servlet-class>jrraporlama.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ImageServlet</servlet-name>
<url-pattern>/image</url-pattern>
</servlet-mapping>

Web uygulamanizda yapmaniz gereken diger islemler:

· JRRaporlama.jar dosyasini uygulamanizin classpath'ine ekleyiniz.

· JasperReports kitapligini http://www.jasperforge.org/ adresinden indiriniz.
Indirdiginiz dosyadan asagidaki kitapliklari uygulamanizin classpath'ine koyabileceginiz gibi Tomcat'in ../common/lib/ext veya ../lib/ext, SunAS icin ise ../domains/{your-domain}/lib klasorune koyabilirsiniz.
jasperreports-2.0.2-javaflow.jar
jasperreports-2.0.2.jar
commons-beanutils-1.7.jar
commons-collections-2.1.jar
commons-digester-1.7.jar
commons-javaflow-20060411.jar
itext-1.3.1.jar
poi-3.0.1-FINAL-20070705.jar
commons-logging-1.0.2.jar
jdt-compiler-3.1.1.jar
groovy-all-1.0.jar
jaxen-1.1.1.jar
jcommon-1.0.0.jar
jfreechart-1.0.0.jar
jpa.jar
poi-3.0.1-FINAL-20070705.jar





Parametreler:



externalContext -

Web uygulamanizdan this.getExternalContext() seklinde bu paramtereyi deger gecirebilirsiniz. Bu paramtre ile Http response ve request'i elde edilir ve Web uygulamanizin Web sayfasina rapor hazirlanarak gonderilir. JRRaporlama kitapligi JSF 1.1 ve JSF 1.2 (WoodStock) kullanilabilinir. Ancak JSF'de rapor sonrasi asagidaki komut olmaldir. this.getFacesContext().responseComplete();

raporTuru - Alinacak raporun turu

Rapor.PDF, Rapor.DOC, Rapor.XLS, Rapor.HTML olabilir.

dBDriver - Veritabani surucusu

MySQL icin: com.mysql.jdbc.Driver, Oracle icin: oracle.jdbc.OracleDriver

dBConnectString - Veritabani baglantisi karakter katari

MySQL icin ornek: jdbc:mysql://localhost:3306/test, Oracle icin ornek: jdbc:oracle:thin:@localhost:1521:test

dBUserName - Veritabani kullanici adi

dBUserPassword - Veritabani kullanicisinin parolasi

reportFileFullPath - Rapor dosyasinin tam yolu ve adi

Örnek : d:/test/test1.jrxml

subReportFolderPath - Raporun alt raporlari var ise alt raporlarin oldugu klasor

Örnek : d:/test/subreports/

parameters - 2 boyutlu Object sınıfında JasperReports sablonuna gecirilecek parametreler



Örnek :



jrraporlama.Rapor rapor = new jrraporlama.Rapor();
Object[] parametreler = new Object[2];
parametreler[0] = "param1";
parametreler[1] = "deger1";

String sonuc = rapor.RaporOlustur(this.getFacesContext(),
Rapor.HTML,
"com.mysql.jdbc.Driver",
"jdbc\:mysql\://localhost/test",
"testuser",
"password",
"test.jrxml",
"c:/test" ,
parametreler);
if (sonuc != null) {
alert1.setType("error");
alert1.setSummary(sonuc);
}

THE NEW JAVA PERSISTENCE API-AN EASY SOLUTION FOR ENTITY PERSISTENCE


ABSTRACT
The aim of the Java EE 5 platform design has been to streamline these features and add convenience, improve performance, reduce development time, and help developers get products to market and enterprise customers that much sooner.
The new version of EJB at the platform Java EE 5 has been dramatically simplified and it is too easy to develop Java Persistence Beans without any coding and without knowledge of persistence provider like TopLink, Hibernate, etc. At this white paper, a sample project will be showcased you using Web service over JPA Beans and you will find attached copy of the EJB project and Web application project in this white paper’s soft copy.

You can read more, please downlod it.

Glassfish ve JDBC BC

Netbeans 6.1 ile gelen Open-ESB JDBC BC (binding component)'i denemek istediğinizde bir türlü çalıştıramadığınızı ve sonuç alamadığınızı göreceksiniz. Aynı problemi Open-ESB sitesinden indireceğiniz NetBeans + GlassFish + Open-ESB'de de yaşıyacaksınız, ancak artık üzülmeyin :) Sorunun nedeni hataları ayıklanmış olan JDBC BC'nun her iki durumda da Netbeans içerisinde ve GlassFish uygulama sunucusunda normal bir şekilde kurulum yapıldığında yer almaması.

Open-ESB : https://open-esb.dev.java.net/

Netbeans : http://www.netbeans.org/


Sorunu aşağıdaki gibi ortadan kaldırabilir ve JDBC BC'yi BPEL diagramınız içerisinde artık kullanabilirsiniz.




Adım 1:

GlassFish uygulama sunucusu JDBC BC bileşenini aşağıdaki adresten indiriniz. İndireceğiniz dosya jdbcbc.jar olmalıdır.

http://download.java.net/jbi/binaries/open-jbi-components/main/nightly/latest/ojc/

Adım 2:

Services sekmesine geçip GlassFish uygulama sunucusunu başlatınız. Uygulama sunucusu çalışır hale geldikten sonra Services sekmesindeki GlassFish bölümündeki seçenekler görülecektir. Bunlardan JBI üzerine gelip "Binding Components"ı bulunuz. "Sun-jdbc-binding" i görüyorsanız.





Sağ fare butonu ile üzerine geldikten sonra shutdown ve ardından uninstall ile kaldırabilirsiniz. Eski JDBC BC'yi kaldırdıktan sonra yine aynı menüden "install" ile indirdiğinizi kurabilirsiniz.



Adım 3:

http://download.java.net/jbi/binaries/open-esb-full-install/nbm/latest/ adresinden org-netbeans-modules-wsdlextensions-jdbc.nbm isimli dosyayı indiniz. Netbeans Tools->Plugins menüsünü kullanarak kurunuz.

Böylece artık JDBC BC ile çalışmaya hazır hale geldiniz.

20 Mayıs 2008 Salı

Tips - Netbeans 6.1 Visual Portlet and Liferay Portal

* Let's consider we developed a Visual JSF portlet at Netbeans and want to deploy to Liferay. You will see deployment error at Glassfish's log :


Error loading deployment descriptors for module [portlet1] Line 132 Column 11 -- Deployment descriptor file WEB-INF/web.xml in archive [portlet1]. cvc-complex-type.2.4.a: Invalid content was found starting with element 'taglib'. One of '{"http://java.sun.com/xml/ns/javaee":jsp-property-group}' is expected.;_RequestID=80651ab6-2ae1-4e3d-a686-a1eeec206d84;"DPL8011: autodeployment failure while deploying the application : Error loading deployment descriptors for module [portlet1] Line 132 Column 11 -- Deployment descriptor file WEB-INF/web.xml in archive [portlet1]. cvc-complex-type.2.4.a: Invalid content was found starting with element 'taglib'. One of '{"http://java.sun.com/xml/ns/javaee":jsp-property-group}' is expected.

Please remove the following section from web.xml and try to deploy:

<jsp-config>
<jsp-property-group>
<url-pattern>*.jspf</url-pattern>
<is-xml>true</is-xml>
</jsp-property-group>
</jsp-config>


* To eliminate lifecycle problem for JSR-286 portlet running at Liferay portal server, insert the following section at the end of portlet.xml file (just before </portlet-app>)

<container-runtime-option>
<name>javax.portlet.escapeXml</name>
<value>false</value>
</container-runtime-option>

17 Mayıs 2008 Cumartesi

NB 6.1 plugin to convert J2EE 1.4 project (Web or portlet) to VWP Java EE 5 (JSF 1.2) project




I modified this plugin (originally written by Winston Prakash) and added some features.

You can follow installation steps at Winston Prakash's blog.
http://blogs.sun.com/winston/entry/vwpprojectconverter


Modified plugin is able to convert old JSF 1.1 Web or portlet project to JSF 1.2. Converted Portlet projects is suitable to JSR-286 only.



NBM File:



Source:

16 Mayıs 2008 Cuma

Reading and writing a properties file

Sometimes we need to read and write some data for remembering purposes to the outside of our project jar/war file.



I wrote some methods to achive these needs.
private Properties readFromPropertiesFile() {
// Read properties file.
Properties prop = new Properties();

try {
prop.load(new FileInputStream("data.properties"));

} catch (IOException e) {
}
return prop;
}



private void writeToPropertiesFile(Properties prop) {
// Write properties file.
try {
prop.store(new FileOutputStream("data.properties"), null);
} catch (IOException e) {
}
}


private String readKey(Properties prop, String key)
{
return prop.getProperty(key);
}



private void writeKey(Properties prop, String key, String value)
{
prop.setProperty(key, value);
}

NB 6.0 plugin to convert J2EE 1.4 project (Web or portlet) to VWP Java EE 5 (JSF 1.2) project

I started to modify VWP Project Converter plugin which developed by Winston Prakash

(http://blogs.sun.com/winston/entry/vwpprojectconverter)

Project that I started will be able to convert old JSF 1.1 Web or portlet project to JSF 1.2. Converted Portlet projects will be suitable to JSR-286 only.

Coming soon !

No more mandatory component binding in Netbeans 6.1 Visual Web



As you know from previous Netbeans versions, when you add a control from palette, control bindings were created without asking you. With Netbeans 6.1 you can add/remove these binding by using context menu.

Sample JSR-286 Netbeans Visual portlet for Liferay Portal

You can download this JSR-286 sample portlet below.


If you want to play and make some modifications, you need :

  • Netbeans 6.1 IDE (Generic Portlet, JSF Portlet Bridge Library and Visual Web JSF Portlet Support plugins)

Just deploying you need :

  • Liferay 5.0.1 or greater
  • GlassFish AS V2UR2

Before deploying this sample portlet you must copy some files to {Glassfish dir}/domains/domain1/lib directory and restart Glassfish server. These files are :

1. Open liferay-portal-dependencies-5.0.1.zip and extract portal-kernel.jar and portal-service.jar (don't use portlet.jar) to {Glassfish dir}/domains/domain1/lib.

2. Find "portlet-api-2.0.jar" and "portlettaglib.jar" under the directory {user dir}\.netbeans\6.1\modules\ext\portalpack and copy them to {Glassfish dir}/domains/domain1/lib.

Enjoy :)