Tuesday, May 07, 2013

How to use primefaces with Jboss 7.1.3


This tutorial will teach us how to use primefaces with jboss 7.1.3.

Requirements:
 1.) primefaces 3.5
 2.) jboss 7.1.3
 3.) maven javaee6 generated project (ear, war, ejb)

Steps:
1.) Add primefaces module in jboss.
  a.) In JBOSS_HOME/modules directory create org/primefaces/main folder.
  b.) Copy primefaces.jar to the folder that has just been created.
  c.) Create module.xml.
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.primefaces">
 <resources>
  <resource-root path="primefaces-3.5.jar"/>
 </resources>
 
 <dependencies>
  <module name="javax.faces.api" />
 </dependencies>
</module>

2.) Add primefaces dependency to ejb/pom.xml
<dependency>
 <groupId>org.primefaces</groupId>
 <artifactId>primefaces</artifactId>
 <version>3.5</version>
</dependency>

3.) In web/pom.xml, exclude primefaces jar in ejb dependency:
<dependency>
 <groupId>com.czetsuya</groupId>
 <artifactId>xxx-ejb</artifactId>
 <type>ejb</type>
 <scope>provided</scope>
 <exclusions>
  <exclusion>
   <groupId>org.primefaces</groupId>
   <artifactId>primefaces</artifactId>
  </exclusion>
 </exclusions>
</dependency>

4.) Add jboss-deployment-structure.xml in ear/src/main/resources/META-INF:
<jboss-deployment-structure>
 <ear-subdeployments-isolated>true</ear-subdeployments-isolated>
  the EAR's lib folder -->
 <deployment>
  <dependencies>
   <module name="org.primefaces" />
   <module name="javax.faces.api" />
  </dependencies>
 </deployment>
</jboss-deployment-structure>
Thursday, March 28, 2013

How to redirect or navigate to a different page with JSF


There are several ways of navigating from 1 page to another in JSF. There are 2 that I often use:

1.) Create a h:commandButton and tie it to an action that returns a string, which maps to a page: example return "home.xhtml".

2.) Using navigation handler:
ConfigurableNavigationHandler navigationHandler = (ConfigurableNavigationHandler) FacesContext.getCurrentInstance().getExternalContext().getApplication().getNavigationHandler();
navigationHandler.performNavigation("home");
Tuesday, March 26, 2013

How to configure jrebel in eclipse with maven


This page is a compilation of instruction on how you can configure your eclipse with maven to autodeploy an ear or war using jrebel.

Prerequisites:
1.) eclipse with maven
2.) jrebel with license

Steps:
1.) Install jrebel plugin to eclipse using this guide:
http://zeroturnaround.com/software/jrebel/download/installing-jrebel-plugin-for-eclipse/

2.) You can ask jrebel to create your jrebel.xml file but for me it's much easier to create one and put it in your resources directory. Example with maven project: src/main/resources. For more details:
http://zeroturnaround.com/software/jrebel/how-to-configure-rebel-xml/

This is how my working configuration looks like:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://www.zeroturnaround.com"
 xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">

 <classpath>
  <dir name="C:\java\git\czetsuya-project\czetsuya-project\czetsuya-project-admin\web\target\classes" />
  <dir name="C:\java\git\czetsuya-project\czetsuya-project\czetsuya-project-admin\web\src\main\resources" />
 </classpath>

 <web>
  <link target="/">
   <dir name="C:\java\git\czetsuya-project\czetsuya-project\czetsuya-project-admin\web\src\main\webapp" />
  </link>
 </web>

</application>

Hope it helps :-)
Friday, March 22, 2013

How to create an instance bean in JavaEE6 using its class


JavaEE6 has really revolutionize the development using CDI (from seam) but there are times when we need to create an instance of a class not by injection but by other means such as Component.getInstance from seam.

In seam we have something like
MyClass myClass = (MyClass) Component.getInstance("MyClass");

In JavaEE6, we do that by:
Bean bean = (Bean) beanManager.getBeans(MyClass.class).iterator().next();
CreationalContext ctx = beanManager.createCreationalContext(bean);
return (MyClass) beanManager.getReference(bean, MyClass.class, ctx);


I use this type of approach normally with FacesConverters.

Search

Loading...