28 September 2011

How to check ROLES in EL in JSF 2 and conditionally render components

 In the below code we are checking for role ADMIN
<h:outputText value="abcd" rendered="#{request.isUserInRole('ADMIN')}"/>

GlassFish 3 server - Enabling JPA for WAR module

My first sample web application in GlassFish 3 server involving JPA 2.0 and GlassFish was spitting out the error "Unable to retrieve EntityManagerFactory for unitName XXX". Other settings were right.
Solution: Edit domain.xml to enable JPA as below. By default JPA is enabled for EJB modules.

<module name="yourwebmodulename">
<engine sniffer="jpa"></engine>

How to have WAR and JAR folders exploded in an EAR project built by Maven

Add the attribute unpack=true (example below)

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<webModule>
<groupId>com.urcompany</groupId>
<artifactId>xxx-web</artifactId>
<contextRoot>/</contextRoot>
<unpack>true</unpack>
</webModule>
<ejbModule>
<groupId>com.urcompany</groupId>
<artifactId>xxx-ejb</artifactId>
<unpack>true</unpack>
</ejbModule>
</modules>
</configuration>
</plugin>