[jboss-user] [JBoss Seam] - Reference a web bean in a seam stateless bean

ector7280 do-not-reply at jboss.com
Wed Feb 21 16:10:58 EST 2007


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>
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4020250#4020250

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4020250



More information about the jboss-user mailing list