This content has been marked as final.
Show 1 reply
-
1. Re: Regarding Outjecting and Injecting
sriramsudheer Feb 29, 2008 5:16 AM (in response to sriramsudheer)This is the following code
1st component:
package com.landmarkSoftware.dv03.deploy.session; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; import javax.ejb.Remove; import javax.ejb.Stateful; import javax.ejb.Stateless; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Destroy; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Out; import org.jboss.seam.annotations.Scope; import org.jboss.seam.log.Log; import org.jboss.seam.security.Identity; import com.landmarkSoftware.dv03.dao.global.AuthenticateDao; import com.landmarkSoftware.dv03.dao.global.GlobalDao; import com.landmarkSoftware.dv03.deploy.entity.global.Function; import com.landmarkSoftware.dv03.deploy.entity.global.Role; import com.landmarkSoftware.dv03.deploy.entity.global.User; import com.landmarkSoftware.dv03.deploy.session.local.IAuthenticatorLocal; @Stateful @Name("authenticator") @Scope(ScopeType.SESSION) public class Authenticator implements IAuthenticatorLocal { @Logger Log log; @In Identity identity; @In GlobalDao globalDao; @Out(value="user") private User authentictedUser; public boolean authenticate() { log.info("authenticating #0", identity.getUsername()); String userName = identity.getUsername(); String password = identity.getPassword(); AuthenticateDao authenticateDao = globalDao.getAuthenticateDao(); User user = authenticateDao.authenticate(userName, password); if(user!= null) { authentictedUser = user; log.info("User Authenticated", authentictedUser.getUserUsername()); return true; }else { return false; } } //The Roles to applications are collection of functions available to user public void installRolesToApplication(User user) { Set<Role> roles = user.getRoles(); for(Role role: roles) { Set<Function> functions = role.getFunctions(); for(Function function: functions) { identity.addRole(function.getFunctionName()); } } } @Remove @Destroy public void destroy() { } }
2nd component:
package com.landmarkSoftware.dv03.deploy.session; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Set; import javax.ejb.Remove; import javax.ejb.Stateful; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.AutoCreate; import org.jboss.seam.annotations.Create; import org.jboss.seam.annotations.Destroy; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import org.jboss.seam.annotations.security.Restrict; import org.jboss.seam.log.Log; import com.landmarkSoftware.dv03.deploy.entity.global.Function; import com.landmarkSoftware.dv03.deploy.entity.global.Role; import com.landmarkSoftware.dv03.deploy.entity.global.User; import com.landmarkSoftware.dv03.deploy.session.local.IAuthenticatedFunctionListRemote; @Stateful @Name("authenticatedFunctionList") @Scope(ScopeType.SESSION) public class AuthenticatedFunctionList implements IAuthenticatedFunctionListRemote, Serializable{ /** * */ private static final long serialVersionUID = 1L; @In(required=false) User user; @Logger Log log; List<Function> authFunctionList; public void loadAuthenticatedFunctionList() { authFunctionList = new ArrayList<Function>(); if (user != null) { log.info("The injected User value is not null"); Set<Role> roles = user.getRoles(); for (Role role : roles) { Set<Function> functions = role.getFunctions(); for (Function function : functions) { authFunctionList.add(function); } } }else { log.info("The Injected User value is Null"); } } @Destroy @Remove public void destroy() { } public List<Function> getAuthFunctionList() { loadAuthenticatedFunctionList(); return authFunctionList; } }
My facelet code: which is a template and so lot of calls to second SFSB:
<ui:repeat xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:rich="http://richfaces.org/rich" value="#{authenticatedFunctionList.authFunctionList}" var="eachFunction"> <s:link value="#{eachFunction.functionName}" propagation="none" rendered="#{identity.loggedIn}"> <br/> </s:link> </ui:repeat>
- {authenticatedFunctionList.authFunctionList} is becoming null second time because of diinjection.