Friday October 02, 2009
TOTD #109: How to convert a JSF managed bean to JSR 299 bean (Web Beans) ?
Content available at http://blog.arungupta.me/2009/10/totd-109-how-to-convert-a-jsf-managed-bean-to-jsr-299-bean-web-beans/>.
Posted by Arun Gupta in General | Comments[3]
|
|
|
|
|
Monday August 17, 2009
TOTD
#93
showed how to get started with Java EE 6
using NetBeans
6.8 M1 and
GlassFish v3 by
building a simple Servlet 3.0 + JPA 2.0 web
application. TOTD
#94 built upon it by using Java Server Faces 2 instead of
Servlet 3.0 for displaying the results. However we are still using a
POJO
for all the database interactions. This works fine if we are only
reading values from the database but that's not how a typical web
application behaves. The web application would typically perform all
CRUD operations. More typically they like to perform one or more CRUD
operations within the context of a transaction. And how do you do
transactions in the context of a web application ? Java EE 6 comes to
your rescue.
The EJB 3.1
specification (another new specification in Java EE 6) allow
POJO classes to be annotated with @EJB and bundled within
WEB-INF/classes of a WAR file. And so you get all transactional
capabilities in your web application very easily.
This Tip
Of The Day (TOTD) shows how
to enhance the application created in TOTD #94 and use EJB 3.1 instead
of the JSF managed bean
for
performing the business logic. There are two ways to achieve this
pattern as described below.
Lets call this TOTD #95.1
| @javax.ejb.Stateless @ManagedBean public class StateList { @PersistenceUnit EntityManagerFactory emf; public List<States> getStates() { return emf.createEntityManager().createNamedQuery("States.findAll").getResultList(); } } |


| @Stateless public class StateBeanBean { @PersistenceUnit EntityManagerFactory emf; public List<States> getStates() { return emf.createEntityManager().createNamedQuery("States.findAll").getResultList(); } } |
| @ManagedBean public class StateList { @EJB StateBeanBean bean; public List<States> getStates() { return bean.getStates(); } } |
| @Stateless public class StateBeanBean { @PersistenceContext EntityManager em; public List<States> getStates() { return em.createNamedQuery("States.findAll").getResultList(); } } |

Posted by Arun Gupta in General | Comments[1]
|
|
|
|
|
Friday August 14, 2009
TOTD
#93
showed how to get started with Java EE 6
using NetBeans
6.8 M1 and
GlassFish v3 by
building a simple Servlet 3.0 + JPA 2.0 web
application. JPA 2.0 + Eclipselink was used for the database
connectivity
and Servlet 3.0 was used for displaying the results to the user. The
sample demonstrated how the two technologies can be mixed to create a
simple web application. But Servlets are meant for server-side
processing rather than displaying the results to end user. JavaServer
Faces 2 (another new specification in Java EE 6) is designed
to fulfill
that purpose.
This Tip
Of The Day (TOTD) shows how
to enhance the application created in TOTD #93 and use JSF 2 for
displaying the results.


| package server; import java.util.List; import javax.faces.bean.ManagedBean; import javax.persistence.EntityManagerFactory; import javax.persistence.PersistenceUnit; import states.States; /** * @author arungupta */ @ManagedBean public class StateList { @PersistenceUnit EntityManagerFactory emf; public List<States> getStates() { return emf.createEntityManager().createNamedQuery("States.findAll").getResultList(); } } |
| Show States |
|
<h:dataTable var="state" value="#{stateList.states}"
border="1"> <h:column><h:outputText value="#{state.abbrev}"/></h:column> <h:column><h:outputText value="#{state.name}"/></h:column> </h:dataTable> |


Posted by Arun Gupta in General | Comments[3]
|
|
|
|
|
Friday April 03, 2009
TOTD # 77: Running Seam examples with GlassFish
![]() |
Seam is a full-stack solution to assemble complex web applications using simple annotated classes, a rich set of UI components, and very little XML. It integrates Ajax and Business Process Modeling with several Java EE technologies such as Java Server Faces (JSF), Java Persistence API (JPA), and Enterprise Java Beans (EJB 3.0). |
| ~/tools/jboss-seam-2.1.1.GA/examples/jpa >ant glassfish Buildfile: build.xml glassfish: initcopy: initpoms: [echo] Setting up dependencies [mkdir] Created dir: /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms [copy] Copying 1 file to /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms [artifact:install] [INFO] Installing /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms/root.pom to . . . . . . init.war: war: [copy] Copying 27 files to /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jpa/exploded-archives-glassfish/jboss-seam-jpa.war [copy] Copying 7 files to /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jpa/exploded-archives-glassfish/jboss-seam-jpa.war/WEB-INF/lib noejb.war: [copy] Copying 18 files to /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jpa/exploded-archives-glassfish/jboss-seam-jpa.war/WEB-INF/lib [copy] Copying 2 files to /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jpa/exploded-archives-glassfish/jboss-seam-jpa.war [copy] Copying 4 files to /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jpa/exploded-archives-glassfish/jboss-seam-jpa.war distributable.war: noejb.archive: [jar] Building jar: /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jpa/dist-glassfish/jboss-seam-jpa.war BUILD SUCCESSFUL Total time: 5 seconds |
| ~/tools/jboss-seam-2.1.1.GA/examples/jpa >~/tools/glassfish/v2.1/glassfish/bin/asadmin
deploy dist-glassfish/jboss-seam-jpa.war Command deploy executed successfully. |



| ~/tools/jboss-seam-2.1.1.GA/examples/hibernate
>ant glassfish Buildfile: build.xml glassfish: initcopy: initpoms: [echo] Setting up dependencies [copy] Copying 1 file to /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms [artifact:install] [INFO] Installing /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms/root.pom to /Users/arungupta/.m2/repository/org/jboss/seam/root/2.1.1.GA/root-2.1.1.GA.pom . . . distributable.war: noejb.archive: [jar] Building jar: /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/hibernate/dist-glassfish/jboss-seam-hibernate.war BUILD SUCCESSFUL Total time: 6 seconds |
| ~/tools/jboss-seam-2.1.1.GA/examples/hibernate
>~/tools/glassfish/v2.1/glassfish/bin/asadmin
deploy dist-glassfish/jboss-seam-hibernate.war Command deploy executed successfully. |
| ~/tools/jboss-seam-2.1.1.GA/examples/jee5/booking
>ant Buildfile: build.xml initcopy: initpoms: [echo] Setting up dependencies [copy] Copying 1 file to /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms [artifact:install] [INFO] Installing /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms/root.pom to /Users/arungupta/.m2/repository/org/jboss/seam/root/2.1.1.GA/root-2.1.1.GA.pom [copy] Copying 1 file to /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms . . . archive: [jar] Building jar: /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jee5/booking/dist/jboss-seam-jee5-booking.jar [jar] Building jar: /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jee5/booking/dist/jboss-seam-jee5-booking.war [jar] Building jar: /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jee5/booking/dist/jboss-seam-jee5-booking.ear BUILD SUCCESSFUL Total time: 5 seconds ~/tools/jboss-seam-2.1.1.GA/examples/jee5/booking >~/tools/glassfish/v2.1/glassfish/bin/asadmin deploy dist/jboss-seam-jee5-booking.ear Command deploy executed successfully. |
Posted by Arun Gupta in Finance | Comments[13]
|
|
|
|
|
Thursday December 11, 2008
TOTD # 59: Alternative JSF implementations on GlassFish - MyFaces and Tomahawk
GlassFish comes
bundled with an industry grade implementation of Java Server Faces
codenamed Mojarra.
It is the
most complete, up-to-date and well-tested JSF implementation
and used pretty
extensively. GlassFish v2 and v3 Prelude ships with JSF
1.2.x-compliant implementation that is defined as part of Java EE 5.
GlassFish v3 trunk contains JSF 2.0-compliant implementation that is
getting defined as part of Java EE 6. The latest version of Mojarra can
be installed from the Update
Center.
But GlassFish does not restrict
you to Mojarra
and instead it embraces other JSF implementations easily. This blog
uses MyFaces,
an alternate JavaServer Faces implementation from Apache, to
demonstrate
that. If you are interested in a brief summary of what it takes to use
these alternate implementations on GlassFish then scroll to the end of
this entry.
![]() |
MyFaces also provides several component libraries such as Tomahawk, Trinidad, and Tobago for building web applications. This blog shows how MyFaces Tomahawk samples can be deployed on GlassFish v2 and v3. The basic integration hooks between GlassFish and other JSF implementations remain the same and are independent of the component library. |
| [#|2008-12-05T11:00:43.710-0800|INFO|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=22;_ThreadName=Thread-43;| deployed with moduleid = myfaces-example-simple-1.1.8|#] [#|2008-12-05T11:00:44.296-0800|INFO|sun-appserver9.1|javax.enterprise.resource.webcontainer.jsf.config|_ThreadID=21; _ThreadName=httpWorkerThread-4848-1;/myfaces-example-simple-1.1.8;|Initializing Sun's JavaServer Faces implementation (1.2_04-b20-p03) for context '/myfaces-example-simple-1.1.8'|#] |

| [#|2008-12-03T16:27:43.935-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=24;_ThreadName=httpSSLWorkerThread-8080-1;| 2008-12-03 16:27:43,935 [httpSSLWorkerThread-8080-1] INFO org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Starting up Tomahawk on the MyFaces-JSF-Implementation |#] [#|2008-12-03T16:27:43.935-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=24;_ThreadName=httpSSLWorkerThread-8080-1;| 2008-12-03 16:27:43,935 [httpSSLWorkerThread-8080-1] ERROR org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Both MyFaces and the RI are on your classpath. Please make sure to use only one of the two JSF-implementations. |
| <?xml version="1.0"
encoding="UTF-8"?> <!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Servlet 2.4//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_4-1.dtd"> <sun-web-app> <class-loader delegate="false"/> <property name="useMyFaces" value="true"/> </sun-web-app> |
| . . . [#|2008-12-05T11:11:25.615-0800|INFO|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=24;_ThreadName=Thread-257;| deployed with moduleid = myfaces-simple-v2|#] [#|2008-12-05T11:11:26.266-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;| 2008-12-05 11:11:26,266 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - Reading standard config org/apache/myfaces/resource/standard-faces-config.xml |#] [#|2008-12-05T11:11:26.290-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;| 2008-12-05 11:11:26,290 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - Reading config jar:file:/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/WEB-INF/lib/tomahawk-1.1.8.jar!/ META-INF/faces-config.xml |#] [#|2008-12-05T11:11:26.309-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:26,308 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - Reading config /WEB-INF/examples-config.xml |#] [#|2008-12-05T11:11:26.337-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:26,337 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - Reading config /WEB-INF/testSuite-config.xml |#] [#|2008-12-05T11:11:26.349-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:26,349 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package : myfaces-api in version : 1.1.6 from path : file:/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/WEB-INF/lib/myfaces-api-1.1.6.jar |#] [#|2008-12-05T11:11:26.350-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:26,350 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package : myfaces-impl in version : 1.1.6 from path : file:/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/WEB-INF/lib/myfaces-impl-1.1.6.jar |#] [#|2008-12-05T11:11:26.350-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:26,350 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - MyFaces-package : tomahawk-sandbox not found. |#] [#|2008-12-05T11:11:26.350-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:26,350 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package : tomahawk in version : 1.1.8 from path : file:/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/WEB-INF/lib/tomahawk-1.1.8.jar |#] . . . [#|2008-12-05T11:11:27.069-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:27,069 [httpWorkerThread-4848-1] INFO org.apache.myfaces.shared_impl.config.MyfacesConfig - Starting up Tomahawk on the RI-JSF-Implementation. |#] [#|2008-12-05T11:11:27.069-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:27,069 [httpWorkerThread-4848-1] INFO org.apache.myfaces.shared_impl.config.MyfacesConfig - Starting up Tomahawk on the MyFaces-JSF-Implementation |#] [#|2008-12-05T11:11:27.070-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:27,070 [httpWorkerThread-4848-1] ERROR org.apache.myfaces.shared_impl.config.MyfacesConfig - Both MyFaces and the RI are on your classpath. Please make sure to use only one of the two JSF-implementations. |#] [#|2008-12-05T11:11:27.070-0800|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=21;_ThreadName=httpWorkerThread-4848-1;|2008-12-05 11:11:27,070 [httpWorkerThread-4848-1] INFO org.apache.myfaces.webapp.StartupServletContextListener - ServletContext '/Users/arungupta/tools/glassfish/v2/ur2/glassfish/domains/domain1/applications/j2ee-modules/myfaces-simple-v2/' initialized. |#] |

| Dec 5, 2008 11:27:17 AM
com.sun.faces.config.ConfigureListener contextInitialized INFO: Initializing Mojarra (1.2_10-b01-FCS) for context '/myfaces-example-simple-1.1.8' Dec 5, 2008 11:27:18 AM com.sun.enterprise.web.WebApplication start INFO: Loading application myfaces-example-simple-1.1.8 at /myfaces-example-simple-1.1.8 Dec 5, 2008 11:27:18 AM org.glassfish.deployment.admin.DeployCommand execute INFO: Deployment of myfaces-example-simple-1.1.8 done is 3470 ms |
| Dec 5, 2008 11:54:54 AM INFO: 2008-12-05 11:54:54,083 [httpWorkerThread-8080-0] INFO org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Starting up Tomahawk on the RI-JSF-Implementation. Dec 5, 2008 11:54:54 AM INFO: 2008-12-05 11:54:54,083 [httpWorkerThread-8080-0] INFO org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Starting up Tomahawk on the MyFaces-JSF-Implementation Dec 5, 2008 11:54:54 AM INFO: 2008-12-05 11:54:54,083 [httpWorkerThread-8080-0] ERROR org.apache.myfaces.shared_tomahawk.config.MyfacesConfig - Both MyFaces and the RI are on your classpath. Please make sure to use only one of the two JSF-implementations. |

| Dec 5, 2008 12:35:17 PM
com.sun.faces.config.ConfigureListener contextInitialized INFO: Initializing Mojarra 2.0.0 (SNAPSHOT b05) for context '/myfaces-example-simple-1.1.8' Dec 5, 2008 12:35:18 PM org.apache.catalina.core.ApplicationContext log SEVERE: WebModule[/myfaces-example-simple-1.1.8]PWC1275: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener java.lang.NoClassDefFoundError: com/sun/facelets/tag/jsf/ComponentHandler at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:675) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) at org.glassfish.web.loader.WebappClassLoader.findClass(WebappClassLoader.java:974) |
| <context-param> <param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name> <param-value>true</param-value> </context-param> |
| Dec 5, 2008 2:50:21 PM
com.sun.faces.config.ConfigureListener contextInitialized INFO: Initializing Mojarra 2.0.0 (SNAPSHOT b05) for context '/myfaces-simple-v3' Dec 5, 2008 2:50:21 PM com.sun.enterprise.web.WebApplication start INFO: Loading application myfaces-simple-v3 at /myfaces-simple-v3 Dec 5, 2008 2:50:21 PM org.glassfish.deployment.admin.DeployCommand execute INFO: Deployment of myfaces-simple-v3 done is 1513 ms |

| <?xml version="1.0"
encoding="UTF-8"?> <!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Servlet 2.4//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_4-1.dtd"> <sun-web-app> <class-loader delegate="false"/> <property name="useBundledJsf" value="true"/> </sun-web-app> |
| . . . Dec 5, 2008 3:19:54 PM INFO: 2008-12-05 15:19:54,786 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - Reading config jar:file:/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/WEB-INF/lib/tomahawk-1.1.8.jar!/ META-INF/faces-config.xml Dec 5, 2008 3:19:54 PM INFO: 2008-12-05 15:19:54,806 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - Reading config /WEB-INF/examples-config.xml Dec 5, 2008 3:19:54 PM INFO: 2008-12-05 15:19:54,828 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - Reading config /WEB-INF/testSuite-config.xml Dec 5, 2008 3:19:54 PM INFO: 2008-12-05 15:19:54,841 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package : myfaces-api in version : 1.1.6 from path : file:/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/WEB-INF/lib/myfaces-api-1.1.6.jar Dec 5, 2008 3:19:54 PM INFO: 2008-12-05 15:19:54,841 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package : myfaces-impl in version : 1.1.6 from path : file:/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/WEB-INF/lib/myfaces-impl-1.1.6.jar Dec 5, 2008 3:19:54 PM INFO: 2008-12-05 15:19:54,841 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - MyFaces-package : tomahawk-sandbox not found. Dec 5, 2008 3:19:54 PM INFO: 2008-12-05 15:19:54,841 [httpWorkerThread-4848-1] INFO org.apache.myfaces.config.FacesConfigurator - Starting up MyFaces-package : tomahawk in version : 1.1.8 from path : file:/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/WEB-INF/lib/tomahawk-1.1.8.jar . . . Dec 5, 2008 3:19:55 PM INFO: 2008-12-05 15:19:55,763 [httpWorkerThread-4848-1] INFO org.apache.myfaces.shared_impl.config.MyfacesConfig - Starting up Tomahawk on the RI-JSF-Implementation. Dec 5, 2008 3:19:55 PM INFO: 2008-12-05 15:19:55,764 [httpWorkerThread-4848-1] INFO org.apache.myfaces.shared_impl.config.MyfacesConfig - Starting up Tomahawk on the MyFaces-JSF-Implementation Dec 5, 2008 3:19:55 PM INFO: 2008-12-05 15:19:55,764 [httpWorkerThread-4848-1] ERROR org.apache.myfaces.shared_impl.config.MyfacesConfig - Both MyFaces and the RI are on your classpath. Please make sure to use only one of the two JSF-implementations. Dec 5, 2008 3:19:55 PM INFO: 2008-12-05 15:19:55,764 [httpWorkerThread-4848-1] INFO org.apache.myfaces.webapp.StartupServletContextListener - ServletContext '/Users/arungupta/tools/glassfish/v3/snapshot/glassfish/domains/domain1/applications/myfaces-simple-v3-usebundled/' initialized. Dec 5, 2008 3:19:55 PM com.sun.enterprise.web.WebApplication start INFO: Loading application myfaces-simple-v3-usebundled at /myfaces-simple-v3-usebundled Dec 5, 2008 3:19:55 PM org.glassfish.deployment.admin.DeployCommand execute INFO: Deployment of myfaces-simple-v3-usebundled done is 1994 ms |

| JSF Implementations | ||
| Mojarra | MyFaces | |
| GlassFish v2 | Default | "useMyFaces" property in "sun-web.xml" |
| GlassFish v3 Prelude | Default | Not supported |
| GlassFish v3 Trunk | Disable Facelets 2.0 in "web.xml" | "useMyFaces"
OR "useBundledJsf" property in "sun-web.xml" Disable Facelets 2.0 in "web.xml" (only for Facelets 1.1.x dependencies) |
Posted by Arun Gupta in web2.0 | Comments[5]
|
|
|
|
|
Thursday November 20, 2008
TOTD #54: Java Server Faces with Eclipse IDE
Ed
pointed me to this excellent
tutorial that explains how JavaServer Faces applications can
be easily created using Eclipse IDE. The article clearly shows all the
steps to create a Java Server Faces application and demonstrates the
following JSF concepts:








Posted by Arun Gupta in web2.0 | Comments[2]
|
|
|
|
|
Friday October 24, 2008
TOTD #51: Embedding Google Maps in Java Server Faces using GMaps4JSF
![]() |
GMaps4JSF allows Google Maps to be easily integrated with any JSF application. This blog shows how to use this library with Mojarra - JSF implementation delivered from the GlassFish community. |
| private float latitude; private float longitude; private String details; @ManagedProperty(value="#{cities}") private Cities cities; private final String BASE_GEOCODER_URL = "http://maps.google.com/maps/geo?"; private final String ENCODING = "UTF-8"; private final String GOOGLE_MAPS_KEY = "GOOGLE_MAPS_API_KEY"; private final String OUTPUT_FORMAT = "CSV"; public String getLatLong() throws IOException { details = cities.getCityName() + ", " + cities.getCountryName(); String GEOCODER_REQUEST = BASE_GEOCODER_URL + "q=" + URLEncoder.encode(details, ENCODING) + "&key=" + GOOGLE_MAPS_KEY + "&output=" + OUTPUT_FORMAT; BufferedReader reader = new BufferedReader( new InputStreamReader( new URL(GEOCODER_REQUEST).openStream())); String line = null; int statusCode = -1; while ((line = reader.readLine()) != null) { // 200,4,37.320052,-121.877636 // status code,accuracy,latitude,longitude statusCode = Integer.parseInt(line.substring(0, 3)); if (statusCode == 200) { int secondComma = line.indexOf(",", 5); int lastComma = line.lastIndexOf(","); latitude = Float.valueOf(line.substring(secondComma+1, lastComma)); longitude = Float.valueOf(line.substring(lastComma+1)); System.out.println("Latitude: " + latitude); System.out.println("Longitude: " + longitude); } } return "map"; } // getters and setters |
| @ManagedBean(name="coords", scope="request") |
| <h:commandButton action="#{coords.getLatLong}" value="map"/> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:m="http://code.google.com/p/gmaps4jsf/"> <head> <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAF9QYjrVEsD9al2QCyg8e-hTwM0brOpm-All5BF6PoaKBxRWWERRHQdtsJnNsqELmKZCKghs54I-0Uw" type="text/javascript"> </script> </head> <body> <m:map latitude="#{coords.latitude}" longitude="#{coords.longitude}" width="500px" height="300px" zoom="14" addStretOverlay="true"> <m:marker draggable="true"> <m:eventListener eventName="dragend" jsFunction="showStreet"/> </m:marker> <m:htmlInformationWindow htmlText="#{coords.details}"/> <m:mapControl name="GLargeMapControl" position="G_ANCHOR_BOTTOM_RIGHT"/> <m:mapControl name="GMapTypeControl"/> </m:map> <br/> <br/> <m:streetViewPanorama width="500px" height="200px" latitude="#{coords.latitude}" longitude="#{coords.longitude}" jsVariable="pano1" /> <script type="text/javascript"> function showStreet(latlng) { pano1.setLocationAndPOV(latlng); } </script> <form jsfc="h:form"> <input jsfc="h:commandButton" action="back" value="Back"/> </form> </body> </html> |
|
<navigation-rule> <from-view-id>/welcome.xhtml</from-view-id> <navigation-case> <from-outcome>map</from-outcome> <to-view-id>/map.xhtml</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <from-view-id>/map.xhtml</from-view-id> <navigation-case> <from-outcome>back</from-outcome> <to-view-id>/welcome.xhtml</to-view-id> </navigation-case> </navigation-rule> |



Posted by Arun Gupta in web2.0 | Comments[8]
|
|
|
|
|
Thursday October 23, 2008
TOTD #50: Mojarra 2.0 EDR2 is now available - Try them with GlassFish v3 and NetBeans 6.5
Yaaay, 50th tip!! The previous 49 tips are available here.
Mojarra EDR2 is now available
- download binary
and/or
source
bundle!
GlassFish
v2 UR2 ships with Mojarra 1.2.0_04 and v3 prelude comes with 1.2.0_10.
The Mojarra binaries in both v2 and v3 can
be easily replaced by the new ones as described in Release
Notes. Additionally, TOTD#
47 explains how to get started with Mojarra 2.0 on GlassFish
v2. This blog will guide you through the steps of installing these bits
on GlassFish v3 Prelude and show how to use them with NetBeans IDE.


Posted by Arun Gupta in web2.0 | Comments[4]
|
|
|
|
|
Friday October 17, 2008
TOTD #49: Converting a JSF 1.2 application to JSF 2.0 - @ManagedBean
This is a follow up to TOTD
#48 which showed how to convert a JSF 1.2 application to use
new features of JSF 2.0. In this blog, we'll talk about a new
annotation added to the JSF 2.0 specification - @ManagedBean.
@ManagedBean is a new annotation in the JSF 2.0 specification. The
javadocs (bundled with the nightly)
clearly defines the purpose of this annotation:
The presence of this
annotation on a class automatically registers the class with the
runtime as a managed bean class. Classes must be scanned for the
presence of this annotation at application startup, before any requests
have been serviced.
Essentially this is an alternative to <managed-bean>
fragment in "faces-config.xml". This annotation injects a class in the
runtime as a managed bean and then can be used accordingly.
Using this annotation, the following "faces-config.xml" fragment from
our application:
| <managed-bean> <managed-bean-name>cities</managed-bean-name> <managed-bean-class>server.Cities</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> <managed-bean> <managed-bean-name>dbUtil</managed-bean-name> <managed-bean-class>server.DatabaseUtil</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> <managed-property> <property-name>cities</property-name> <value>#{cities}</value> </managed-property> </managed-bean> |
| @Entity @Table(name = "cities") @ManagedBean(name="cities", scope="request") @NamedQueries({@NamedQuery(...)}) public class Cities implements Serializable { |
| @ManagedBean(name="dbUtil", scope="request") public class DatabaseUtil { @ManagedProperty(value="#{cities}") private Cities cities; |
Posted by Arun Gupta in web2.0 | Comments[10]
|
|
|
|
|
Wednesday October 15, 2008
TOTD #48: Converting a JSF 1.2 application to JSF 2.0 - Facelets and Ajax
TOTD
#47 showed how to deploy a JSF 1.2 application (using
Facelets and Ajax/JSF Extensions) on Mojarra
2.0-enabled GlassFish.
In this blog we'll use new features added in JSF 2.0 to
simplify our
application:
|
<application> <view-handler>com.sun.facelets.FaceletViewHandler</view-handler> </application> |
|
<init-param> <param-name>javax.faces.LIFECYCLE_ID</param-name> <param-value>com.sun.faces.lifecycle.PARTIAL</param-value> </init-param> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"> <ui:composition> <h:head> <h1><h:outputText value="What city do you like ?" /></h1> </h:head> <h:body> <h:form prependId="false"> <h:panelGrid columns="2"> <h:outputText value="CityName:"/> <h:inputText value="#{cities.cityName}" title="CityName" id="cityName" required="true" onkeyup="javax.faces.Ajax.ajaxRequest(this, event, { execute: 'cityName', render: 'city_choices'});"/> <h:outputText value="CountryName:"/> <h:inputText value="#{cities.countryName}" title="CountryName" id="countryName" required="true"/> </h:panelGrid> <h:commandButton action="#{dbUtil.saveCity}" value="submit"/> <br/><br/> <h:outputText id="city_choices" value="#{dbUtil.cityChoices}"></h:outputText> <br/><br/> <h:message for="cityName" showSummary="true" showDetail="false" style="color: red"/><br/> <h:message for="countryName" showSummary="true" showDetail="false" style="color: red"/> </h:form> </h:body> <h:outputScript name="ajax.js" library="javax.faces" target="header"/> </ui:composition> </html> |

Posted by Arun Gupta in web2.0 | Comments[4]
|
|
|
|
|
Tuesday October 14, 2008
TOTD #47: Getting Started with Mojarra 2.0 nightly on GlassFish v2
Java Server Faces 2.0 specification
(JSR 314,
EDR2) and implementation
(soon to be EDR2) are brewing. This blog shows how to get started with Mojarra
- Sun's implementation of JSF.
GlassFish v2 comes bundled with Mojarra 1.2_04 which allows you to
deploy a JSF 1.2 application. This blog explains how you can update
GlassFish v2 to use Mojarra 2.0 nightly. And then it deploys a simple
JSF 1.2-based application on this updated GlassFish instance, there by
showing that your existing JSF 1.2 apps will continue to work with
Mojarra 2.0-enabled GlassFish. This is an important step because it
ensures no regression, unless it was a compatibility fix :)



Posted by Arun Gupta in web2.0 | Comments[5]
|
|
|
|
|
Monday September 22, 2008
TOTD #46: Facelets with Java Server Faces 1.2
This blog updates TOTD
#45 to use Facelets
as view technology.
Powerful templating system, re-use and ease-of-development,
designer-friendly are the key benefits of
Facelets. Facelets are already an integral part of Java Server Faces
2.0. But this blog shows how to use them with JSF 1.2.

| <context-param> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> <param-value>.xhtml</param-value> </context-param> |

| <application> <view-handler>com.sun.facelets.FaceletViewHandler</view-handler> </application> |


|
<form
jsfc="h:form"> <input jsfc="h:commandButton" action="back" value="Back"/> </form> |

|
<navigation-rule> <from-view-id>/welcome.xhtml</from-view-id> <navigation-case> <from-outcome>submit</from-outcome> <to-view-id>/result.xhtml</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <from-view-id>/result.xhtml</from-view-id> <navigation-case> <from-outcome>back</from-outcome> <to-view-id>/welcome.xhtml</to-view-id> </navigation-case> </navigation-rule> |
![]() |
![]() |
![]() |
![]() |
Posted by Arun Gupta in web2.0 | Comments[2]
|
|
|
|
|
Wednesday September 17, 2008
TOTD #45: Ajaxifying Java Server Faces using JSF Extensions
TOTD
#42 explained how to create a simple Java Server Faces
application using NetBeans 6.1 and deploy on GlassFish. In the process
it explained some basic
JSF concepts as well. If you remember, it built an application that
allows you to create a database of cities/country of your choice. In
that application, any city/country combination can be entered twice and
no errors are reported.
This blog entry extends TOTD
#42 and show the list of cities, that have already been
entered,
starting with the letters entered in the text box. And instead of
refreshing the entire page, it uses JSF Extensions
to make an Ajax call to the endpoint and show the list of cities based
upon the text entered. This behavior is similar to Autocomplete
and shows the suggestions in a separate text box.
Let's get started!
| ~/tools >gunzip -c ~/Downloads/jsf-extensions-0.1.tar.gz | tar xvf - |

| <%@taglib prefix="jsfExt" uri="http://java.sun.com/jsf/extensions/dynafaces" %> |

| <jsfExt:scripts /> |


| onkeyup="DynaFaces.fireAjaxTransaction(this, { execute: 'cityName', render: 'city_choices', immediate: true});" |

| <h:outputText id="city_choices" value="#{dbUtil.cityChoices}"></h:outputText> |

|
<init-param> <param-name>javax.faces.LIFECYCLE_ID</param-name> <param-value>com.sun.faces.lifecycle.PARTIAL</param-value> </init-param> |


| @NamedQuery(name = "Cities.findSimilarName",
query = "SELECT c FROM Cities c WHERE LOWER(c.cityName) LIKE
:searchString"), |

| public
Collection<Cities> getCityChoices() { Collection<Cities> allCities = new ArrayList<Cities>(); if (cities.getCityName() != null && !cities.getCityName().equals("")) { List list = entityManager.createNamedQuery("Cities.findSimilarName"). setParameter("searchString", cities.getCityName().toLowerCase() + "%"). getResultList(); for (int i = 0; i < list.size(); i++) { allCities.add((Cities) list.get(i)); } } return allCities; } |






Posted by Arun Gupta in web2.0 | Comments[3]
|
|
|
|
|
Wednesday August 20, 2008
TOTD #42: Hello JavaServer Faces World with NetBeans and GlassFish
This TOTD (Tip
Of The Day) shows how to
create a simple Java
Server Faces application using NetBeans IDE 6.1. This
is my first ever Java Server Faces application :) Much more
comprehensive applications are already available in NetBeans
and GlassFish
tutorials.
The application is really simple - it allows you to create a database
of cities/country that you like. You enter the city & country
name on a page and click on Submit. This stores the data entered in the
backend database and displays all the stored values in a new page. This
application demonstrates simple JSF concepts:


| create table cities(id integer AUTO_INCREMENT, city_name varchar(20), country_name varchar(20), PRIMARY KEY(id)); |
| @NamedQuery(name = "Cities.findAll", query = "SELECT c FROM Cities c"), |


| private Cities cities; public void setCities(Cities cities) { this.cities = cities; } |
| <managed-bean> <managed-bean-name>cities</managed-bean-name> <managed-bean-class>server.Cities</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> <managed-bean> <managed-bean-name>dbUtil</managed-bean-name> <managed-bean-class>server.DatabaseUtil</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> <managed-property> <property-name>cities</property-name> <value>#{cities}</value> </managed-property> </managed-bean> |
|
@PersistenceContext(unitName="CitiesPU") private EntityManager entityManager; @Resource UserTransaction utx; |
| public
Collection<Cities> getAllCities() { Collection<Cities> allCities = new ArrayList<Cities>(); List list = entityManager.createNamedQuery("Cities.findAll").getResultList(); for (int i = 0; i < list.size(); i++) { allCities.add((Cities)list.get(i)); } return allCities; } |
| public String saveCity() throws
NotSupportedException, SystemException, RollbackException,
HeuristicMixedException, HeuristicRollbackException { utx.begin(); entityManager.persist(cities); utx.commit(); return "submit"; } |



| <h2>Detail</h2> <h:form> <h:panelGrid columns="2"> <h:outputText value="Id:"/> <h:outputText value="#{anInstanceOfserver.Cities.id}" title="Id" /> <h:outputText value="CityName:"/> <h:outputText value="#{anInstanceOfserver.Cities.cityName}" title="CityName" /> <h:outputText value="CountryName:"/> <h:outputText value="#{anInstanceOfserver.Cities.countryName}" title="CountryName" /> </h:panelGrid> </h:form> |
| <h2>Detail</h2> <h:form> <h:panelGrid columns="2"> <h:outputText value="CityName:"/> <h:inputText value="#{cities.cityName}" title="CityName" id="cityName" required="true"/> <h:outputText value="CountryName:"/> <h:inputText value="#{cities.countryName}" title="CountryName" id="countryName" required="true"/> </h:panelGrid> </h:form> |
| <h:commandButton action="#{dbUtil.saveCity}" value="submit"/> |
| <br><br> <h:message for="cityName" showSummary="true" showDetail="false" style="color: red"/><br> <h:message for="countryName" showSummary="true" showDetail="false" style="color: red"/> |
| <%@taglib prefix="f"
uri="http://java.sun.com/jsf/core"%> <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%> |

| <f:view> <h:form> <h1><h:outputText value="List"/></h1> <h:dataTable value="#{arrayOrCollectionOfserver.Cities}" var="item"> <h:column> <f:facet name="header"> <h:outputText value="Id"/> </f:facet> <h:outputText value=" #{item.id}"/> </h:column> <h:column> <f:facet name="header"> <h:outputText value="CityName"/> </f:facet> <h:outputText value=" #{item.cityName}"/> </h:column> <h:column> <f:facet name="header"> <h:outputText value="CountryName"/> </f:facet> <h:outputText value=" #{item.countryName}"/> </h:column> </h:dataTable> </h:form> </f:view> |
| <h:dataTable value="#{dbUtil.allCities}" var="item"> |
| <h:form> <h:commandButton action="back" value="back"/> </h:form> |

|
<navigation-rule> <from-view-id>/welcomeJSF.jsp</from-view-id> <navigation-case> <from-outcome>submit</from-outcome> <to-view-id>/result.jsp</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <from-view-id>/result.jsp</from-view-id> <navigation-case> <from-outcome>back</from-outcome> <to-view-id>/welcomeJSF.jsp</to-view-id> </navigation-case> </navigation-rule> |




Posted by Arun Gupta in web2.0 | Comments[21]
|
|
|
|
|
Thursday July 24, 2008
Job Opportunity in GlassFish Web Container Team
What's common between
Posted by Arun Gupta in web2.0 | Comments[0]
|
|
|
|
|
Today's Page Hits: 2762
Total # blog entries: 994
| « November 2009 | ||||||
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
1 | 2 | 4 | 6 | 7 | ||
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | |||||
| Today | ||||||