2 Replies Latest reply on Feb 23, 2007 11:16 AM by J.R. Ector

    Reference a web bean in a seam stateless bean

    J.R. Ector Newbie

      I'm using Seam 1.1.6 with ICEFaces 1.5.3 I built a tree with a panel stack.
      I need to be able to execute my business logic and then set the selected panel to the page that will contain the generated output.

      I can forward to the page by itself but, I'd like to stay on the page with the tree and only replace the panel to the right of the tree.

      Does anyone know how to gain access to a web bean from inside a stateless session bean?
      Is there another way to do this?

      JR

      Here's the code:

      faces-config.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
      
      <faces-config>
       <managed-bean>
       <managed-bean-name>panelStack</managed-bean-name>
       <managed-bean-class>gov.dot.marad.util.web.PanelStackBean</managed-bean-class>
       <managed-bean-scope>request</managed-bean-scope>
       </managed-bean>
       <managed-bean>
       <managed-bean-name>item</managed-bean-name>
       <managed-bean-class>gov.dot.marad.util.web.PanelSelectUserObject</managed-bean-class>
       <managed-bean-scope>request</managed-bean-scope>
       </managed-bean>
       <navigation-rule>
       <from-view-id>/userLogin.jspx</from-view-id>
       <navigation-case>
       <from-outcome>success</from-outcome>
       <to-view-id>/treeNavigation.jspx</to-view-id>
       <redirect/>
       </navigation-case>
       <navigation-case>
       <from-outcome>failure</from-outcome>
       <to-view-id>/userLogin.jspx</to-view-id>
       <redirect/>
       </navigation-case>
       </navigation-rule>
       <navigation-rule>
       <from-view-id>/createUser.jspx</from-view-id>
       <navigation-case>
       <from-outcome>success</from-outcome>
       <to-view-id>/treeNavigation.jspx</to-view-id>
       <redirect/>
       </navigation-case>
       <navigation-case>
       <from-outcome>failure</from-outcome>
       <to-view-id>/createUser.jspx</to-view-id>
       <redirect/>
       </navigation-case>
       </navigation-rule>
       <navigation-rule>
       <from-view-id>/treeNavigation.jspx</from-view-id>
       <navigation-case>
       <from-outcome>failure</from-outcome>
       <to-view-id>/userLogin.jspx</to-view-id>
       <redirect/>
       </navigation-case>
       </navigation-rule>
       <!-- A phase listener is needed by all Seam applications -->
      
       <lifecycle>
       <phase-listener>
       org.jboss.seam.jsf.TransactionalSeamPhaseListener
       </phase-listener>
       </lifecycle>
      </faces-config>
      


      Stateless Bean

      
      import gov.dot.marad.persistence.ejb.model.Users;
      import gov.dot.marad.util.ApplicationProperties;
      import gov.dot.marad.util.EroomNameSpaceContext;
      import gov.dot.marad.util.eroom.BuildSoapCommand;
      import gov.dot.marad.util.eroom.SendEroomXml;
      import gov.dot.marad.util.web.ReportBean;
      
      import java.io.ByteArrayInputStream;
      import java.text.DateFormat;
      import java.text.ParseException;
      import java.text.SimpleDateFormat;
      import java.util.ArrayList;
      import java.util.Calendar;
      import java.util.List;
      
      import javax.ejb.Stateless;
      import javax.xml.xpath.XPath;
      import javax.xml.xpath.XPathConstants;
      import javax.xml.xpath.XPathExpressionException;
      import javax.xml.xpath.XPathFactory;
      
      import org.apache.xml.dtm.ref.DTMNodeList;
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.log.Log;
      import org.w3c.dom.DOMException;
      import org.xml.sax.InputSource;
      
      @Stateless
      @Name("link")
      public class LinkAction implements Link
      {
      
       @Logger
       private Log log;
      
       @In
       private Users users;
      
       @DataModel
       private List<ReportBean> reports;
      
       @Factory("reports")
       public String create()
       {
       log.info("Enter create");
      
       String reply = "failure";
       String path = null;
       byte[] command = null;
       byte[] response = null;
      
       ...
       int i = 0;
       // Store in a List and outject to next page
       reports = new ArrayList<ReportBean>();
       while (i < nodes)
       {
       ReportBean rb = new ReportBean();
       String name = nameNodes.item(i).getNodeValue();
       String id = nameNodes.item(i + 1).getNodeValue();
       rb.setLink(filePath + "/" + id + "/" + name);
       Calendar cal = Calendar.getInstance();
       String dateTime = nameNodes.item(i + 2).getNodeValue();
       String[] date = dateTime.split("T");
       SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
       cal.setTime(fmt.parse(date[0]));
       rb.setCreateDate(cal.getTime());
       rb.setName(name);
       rb.setCreator(nameNodes.item(i + 3).getNodeValue());
       String project = nameNodes.item(i + 4).getNodeValue();
       String[] projectName = project.split("/");
       rb.setProject(projectName[1]);
       reports.add(rb);
      
       i += 5;
       }
       } catch (XPathExpressionException e)
       {
       // TODO Auto-generated catch block
       e.printStackTrace();
       } catch (DOMException e)
       {
       // TODO Auto-generated catch block
       e.printStackTrace();
       } catch (ParseException e)
       {
       // TODO Auto-generated catch block
       e.printStackTrace();
       }
      
       return "/createLink.jspx";
       }
      
      }
      


      treenavigation.jspx

      <f:view xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:ice="http://www.icesoft.com/icefaces/component"
       xmlns:s="http://jboss.com/products/seam/taglib">
      
       <ice:outputDeclaration doctypeRoot="HTML"
       doctypePublic="-//W3C//DTD HTML 4.01 Transitional//EN"
       doctypeSystem="http://www.w3.org/TR/html4/loose.dtd" />
      
       <html>
       <head>
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
       <title>Tree Component Tutorial</title>
       <link href="./xmlhttp/css/xp/xp.css" rel="stylesheet" type="text/css" />
       </head>
      
       <body>
       <h2>Tree Selection Example</h2>
       <ice:form>
      
       <ice:panelGrid columns="2" cellspacing="5">
      
       <!-- first column, for tree navigation -->
       <ice:panelGroup style="border: 1px solid gray; height: 300px;">
       <!--
       This is a very links tree comprising of only text nodes. The
       expand and contract images are rendered because the "imageDir"
       attribute on the tree component has been set to a known path.
       -->
       <ice:tree id="tree" value="#{navTree.model}" var="item"
       hideRootNode="false" hideNavigation="false"
       imageDir="./xmlhttp/css/xp/css-images/">
       <ice:treeNode>
       <f:facet name="icon">
       <ice:panelGroup style="display: inline">
       <h:graphicImage value="#{item.userObject.icon}" />
       </ice:panelGroup>
       </f:facet>
       <f:facet name="content">
       <ice:panelGroup style="display: inline">
       <h:commandLink
       actionListener="#{item.userObject.selectPanelStackPanel}"
       value="#{item.userObject.text}" />
       </ice:panelGroup>
       </f:facet>
       </ice:treeNode>
       </ice:tree>
       </ice:panelGroup>
      
       <!-- Second column, for panel stack -->
       <ice:panelGroup style="border: 1px solid gray; width:350px ">
       <ice:panelStack selectedPanel="#{panelStack.selectedPanel}"
       styleClass="">
      
       <!-- splash panel -->
       <ice:panelGroup id="splash">
       <h3>Splash Page</h3>
      
       <p>Click on the tree nodes to change the slected panel in the
       panel stack component.</p>
       </ice:panelGroup>
      
       <!-- ICEfaces panel -->
       <ice:panelGroup id="icefaces">
       <jsp:directive.include file="./createFolder.jspx" />
       </ice:panelGroup>
      
       <!-- ICEbrowser panel -->
       <ice:panelGroup id="icebrowser">
       <s:link action="#{link.create}" value="Reports" />
       </ice:panelGroup>
      
       <!-- ICEpdf panel -->
       <ice:panelGroup id="icepdf">
       <h3>ICEpdf</h3>
      
       <p>The leading Java PDF document rendering and viewing
       solution designed to be easily integrated into Java enterprise
       applications.</p>
       </ice:panelGroup>
      
       <!-- Sub node 0-->
       <ice:panelGroup id="sub-node-0">
       <h3>Sub Node Zero</h3>
      
       <p>Say what?</p>
       </ice:panelGroup>
      
       <!-- Sub node 1 -->
       <ice:panelGroup id="sub-node-1">
       <h3>Sub Node One</h3>
      
       <p>Damn Skippy!</p>
       </ice:panelGroup>
       </ice:panelStack>
      
       </ice:panelGroup>
      
       </ice:panelGrid>
      
       </ice:form>
       </body>
       </html>
      </f:view>
      


        • 1. Re: Reference a web bean in a seam stateless bean
          Norman Richards Master

          I don't understand your example, but you can inject a JSF managed bean using @In(value="#{facesBean}").

          • 2. Re: Reference a web bean in a seam stateless bean
            J.R. Ector Newbie

            Hi Norman,

            I tried that but I got a NoClassDefFoundError from that bean.
            I'm confused because I don't have that problem in my tree bean
            that imports that same class. Of course it's not injected, is that the
            difference?

            JR

            2007-02-23 11:05:48,031 WARN [org.jboss.system.ServiceController] Problem starting service jboss.j2ee:service=EJB3,module=cppms.jar
            
            java.lang.NoClassDefFoundError: com/icesoft/faces/component/tree/IceUserObject
            
             at java.lang.ClassLoader.defineClass1(Native Method)
            
             at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
            
             at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
            
             at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
            
             at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
            
             at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
            
             at java.security.AccessController.doPrivileged(Native Method)
            
             at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            
             at org.jboss.mx.loading.RepositoryClassLoader.findClassLocally(RepositoryClassLoader.java:672)
            
             at org.jboss.mx.loading.RepositoryClassLoader.findClass(RepositoryClassLoader.java:652)
            
             at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
            
             at org.jboss.mx.loading.RepositoryClassLoader.loadClassLocally(RepositoryClassLoader.java:190)
            
             at org.jboss.mx.loading.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:131)
            
             at org.jboss.mx.loading.LoadMgr3.nextTask(LoadMgr3.java:399)
            
             at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:517)
            
             at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:405)
            
             at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
            
             at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
            
             at java.lang.Class.getDeclaredFields0(Native Method)
            
             at java.lang.Class.privateGetDeclaredFields(Class.java:2259)
            
             at java.lang.Class.getDeclaredFields(Class.java:1715)
            
             at org.jboss.injection.InjectionUtil.processFieldAnnotations(InjectionUtil.java:131)
            
             at org.jboss.injection.InjectionUtil.processAnnotations(InjectionUtil.java:173)
            
             at org.jboss.ejb3.EJBContainer.processMetadata(EJBContainer.java:270)
            
             at org.jboss.ejb3.SessionContainer.processMetadata(SessionContainer.java:116)
            
             at org.jboss.ejb3.Ejb3Deployment.processEJBContainerMetadata(Ejb3Deployment.java:273)
            
             at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:322)
            
             at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:91)
            
             at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
            
             at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
            
             at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
            
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            
             at java.lang.reflect.Method.invoke(Method.java:585)
            
             at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
            
             at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
            
             at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
            
             at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
            
             at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
            
             at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
            
             at $Proxy0.start(Unknown Source)
            
             at org.jboss.system.ServiceController.start(ServiceController.java:417)
            
             at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
            
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            
             at java.lang.reflect.Method.invoke(Method.java:585)
            
             at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
            
             at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
            
             at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
            
             at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
            
             at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
            
             at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
            
             at $Proxy28.start(Unknown Source)
            
             at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:449)
            
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            
             at java.lang.reflect.Method.invoke(Method.java:585)
            
             at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
            
             at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
            
             at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
            
             at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
            
             at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
            
             at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
            
             at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
            
             at org.jboss.ws.integration.jboss.DeployerInterceptor.start(DeployerInterceptor.java:92)
            
             at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
            
             at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
            
             at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
            
             at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
            
             at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
            
             at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
            
             at $Proxy29.start(Unknown Source)
            
             at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
            
             at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
            
             at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
            
             at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
            
             at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
            
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            
             at java.lang.reflect.Method.invoke(Method.java:585)
            
             at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
            
             at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
            
             at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
            
             at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
            
             at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
            
             at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
            
             at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
            
             at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
            
             at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
            
             at $Proxy6.deploy(Unknown Source)
            
             at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
            
             at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:610)
            
             at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
            
             at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
            
             at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)