Facelets, (JBOSS) Seam, Netbeans and Glassfish
This posting demonstrates that we don't have to package components.xml
with sampleProject-war.
Working on second sample from :
Recent publication: Facelets, (JBOSS) Seam, Netbeans and Glassfish
I have commented out second entry in components.xml:-
<!DOCTYPE components PUBLIC
"-//JBoss/Seam Component Configuration DTD 1.1//EN"
"http://jboss.com/products/seam/components-1.1.dtd">
<components>
<component name="org.jboss.seam.core.init">
<property name="debug"> true </property>
</component>
<!--
<component name="org.jboss.seam.core.init">
<property name="jndiPattern"> java:comp/env/sampleProject-ejb/#{ejbName}/local </property>
</component>
-->
<component name="entityManager" class="org.jboss.seam.core.ManagedPersistenceContext">
<property name="persistenceUnitJndiName"> java:/sampleProject-ejbPU</property>
</component>
</components>
and kept web.xml's corresponding entry in place:-
<context-param>
<description>
</description>
<param-name>org.jboss.seam.core.init.jndiPattern</param-name>
<param-value>java:comp/env/sampleProject?ejb/#{ejbName}/local</param-value>
</context-param>
<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<filter>
<filter-name>SeamRedirectFilter </filter-name>
<filter-class>org.jboss.seam.servlet.SeamRedirectFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SeamRedirectFilter </filter-name>
<url-pattern>*.xhtml</url-pattern>
</filter-mapping>
<filter>
<filter-name>SeamExceptionFilter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamExceptionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SeamExceptionFilter </filter-name>
<url-pattern >*.xhtml</url-pattern>
</filter-mapping>
<ejb-local-ref>
<ejb-ref-name>sampleProject?ejb/ActionBean/local</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>dummy.ActionLocal</local>
<ejb-link >ActionBean</ejb-link>
</ejb-local-ref>
Packaging components.xml with sampleProject-war, generated following
entry into C: \Solaris\AppServer\domains\domain1\logs\server.log during deployment:-
[#|2007-01-04T13:58:38.265+0300|WARNING|sun-appserver-pe9.0|javax.enterprise.resource.webcontainer.jsf.lifecycle|
_ThreadID=15;_ThreadName=httpWorkerThread-8080-1;_RequestID=02b398d6-1127-4c3d-9444-5c446d01a0a5;|
Could not instantiate Seam component:
action org.jboss.seam.InstantiationException:
Could not instantiate Seam component: action
at org.jboss.seam.Component.newInstance(Component.java:1722)
at org.jboss.seam.Component.getInstance(Component.java:1625)
at org.jboss.seam.Component.getInstance(Component.java:1592)
at org.jboss.seam.Component.getInstance(Component.java:1586)
at org.jboss.seam.jsf.SeamELResolver.getValue(SeamELResolver.java:39)
. . . . . . . . .
Configuration suggested above didn’t.
However entry:-
[#|2007-01-05T12:59:02.046+0300|WARNING|sun-appserver-pe9.0|javax.enterprise.system.core.classloading|
_ThreadID=11;_ThreadName=httpWorkerThread-4848-0;_RequestID=6735512c-cb12-4daf-9af8-406d320f710d;|
Input stream has been finalized or forced closed without being explicitly closed; stream instantiation
reported in following stack trace
java.lang.Throwable
at com.sun.enterprise.loader.EJBClassLoader$SentinelInputStream.(EJBClassLoader.java:1123)
at com.sun.enterprise.loader.EJBClassLoader.getResourceAsStream(EJBClassLoader.java:788)
. . . . . . . . . ..
showed up in both cases during deployment , but didn't affect running application
No packaging components.xml with sapmleProject-war has been done before running
project.Regarding proper packaging view also:-
Packaging files with projects issues in NetBeans 5.5
Snapshots:-
Unload NetBeans 5.5 and run deployed apps:-
Load NetBeans and perform database control:-
We are going to make a slight modification to original project.
*****************
ActionLocal.java
*****************
package dummy;
import javax.ejb.Local;
/**
* This is the business interface for Action enterprise bean.
*/
@Local
public interface ActionLocal {
public String registration ();
}
*********************
ActionBean.java
*********************
package dummy;
import dummy.entity.User;
import java.util.List;
import javax.ejb.Stateless;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Outcome;
import org.jboss.seam.ejb.SeamInterceptor;
@Stateless
@Name( "action" )
public class ActionBean implements ActionLocal {
@In( create=true , required=true )
User user;
@PersistenceContext ( )
private EntityManager em;
public ActionBean ( ) { }
public String registration (){
List persons = em.createQuery("select x from User x where x.username=:username").setParameter("username", user.getUsername()).getResultList();
if (persons.size()==0)
{
em.persist(user);
return "success";
}
else
{
return "repeat";
}
}
}
***************************************************************
First client for sampleTemplate - template-client.xhtm
***************************************************************
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<body>
This text above will not be displayed.
<ui:composition template="/template.xhtml">
This text will not be displayed.
<ui:define name="title">
Registration Form
</ui:define>
This text will also not be displayed.
<ui:define name="body">
<ui:define name="content">
<h:form>
<h:inputText id="username" value="#{user.username}"/>
<h:inputText id="password" value="#{user.password}"/>
<h:commandButton value="Sign in" action="#{action.registration}"/>
</h:form>
</ui:define>
</ui:define>
This text will not be displayed.
</ui:composition>
This text below will also not be displayed.
</body>
</html>
****************************************************************
Second client for sampleTemplate -TemplateClientOk.xhtml
****************************************************************
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<body>
<ui:composition template="sampleTemplate.xhtml">
<ui:define name="top">
Registration done for:
</ui:define>
<ui:define name="content">
<h:form>
<h:outputText id="username" value="#{user.username}"/>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
**************************************************************
Third client for sampleTemplate -TemplateClientNO.xhtml
**************************************************************
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<body>
<ui:composition template="sampleTemplate.xhtml">
<ui:define name="top">
Already registered user's name:
</ui:define>
<ui:define name="content">
<h:form>
<h:outputText id="username" value="#{user.username}"/>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
*****************************
Add to faces-config.xml
*****************************
<navigation-rule>
<from-view-id>/template-client.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/templateClientOK.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>repeat</from-outcome>
<to-view-id>/TemplateClientNO.xhtml</to-view-id>
</navigation-case>
</navigation-rule>