using: JBoss 4.0.5.GA and Seam 1.2.1.GA
We noticed today that the SFSB's take the conversation context by default. If
the conversation context is not properly managed using @Begin/@End annotations
in the SFSB, then it appears that the destroy() method is called after the next
JSF is rendered.
In the following example, we're using only one SFSB in the Seam app and
managing the conversation context by the @Begin(join=true) and @End
annotations. If I use @Begin instead of @Begin(join=true), I get a runtime
exception asking me to use @Begin(join=true) instead. When I used
@Begin(join=true), the use case was executed successfully.
Why must I do this if there is no other conversation to join (as far as I
know)? There are two JSF's and one SFSB in this case. Excuse the code, it's
in "refactor me"/cleanup mode. thx.
|
| package com.cox.beans.session;
|
| import java.sql.CallableStatement;
| import java.sql.Connection;
| import java.sql.DriverManager;
| import java.sql.ResultSet;
| import java.sql.ResultSetMetaData;
| import java.sql.SQLException;
| import java.util.ArrayList;
| import java.util.HashMap;
| import java.util.List;
| import java.util.Vector;
|
| import javax.ejb.Remove;
| import javax.ejb.Stateful;
| import javax.faces.event.AbortProcessingException;
| import javax.faces.event.ValueChangeEvent;
| import javax.faces.model.SelectItem;
|
| import org.apache.log4j.Logger;
| import org.jboss.seam.annotations.Begin;
| import org.jboss.seam.annotations.Destroy;
| import org.jboss.seam.annotations.End;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.security.Identity;
|
|
| @Stateful
| @Name("userRoleSearch")
| public class userRoleSearchSLSB implements userRoleSearchSLSBLocal {
|
| String searchStringFirstName;
| String searchStringLastName;
| private String selName;
|
| Logger log = Logger.getLogger(this.getClass());
|
| // Connection con = null;
| CallableStatement cstmt = null;
| // ResultSet rs = null;
| HashMap hm = null;
| HashMap allRolesForUser = null;
| String url =
//"jdbc:sqlserver://CORG0DV01:1433;databaseName=JavaTestDB";
|
"jdbc:sqlserver://CORG0DV02:3220;databaseName=boBETS";
| String userName = "_AppUser_JavaTestAcct";
| String password = "JavaTestAcct";
| boolean isDisplay = false;
| int count =0;
| String selectedUserId1 = null;
| HashMap<String, String> selectedUserId = new HashMap<String, String>();
| HashMap<String, String> counter = new HashMap<String, String>();
| HashMap<String, String> defaultRolesForUserHashMap = new
HashMap<String, String>();
| HashMap<String, String> headerRolesHashMap = new HashMap<String,
String>();
|
| ArrayList al = null;
| List<SelectItem> defaultRolesForUserList;
|
|
| String [] adminUserRolesStrArr;
| String [] otherUserRolesStrArr;
| String [] defaultUserRolesStrArr;
| HashMap otherUserRolesHashMap;
| HashMap adminUserRolesHashMap;
| HashMap defaultUserRolesHashMap;
| HashMap<String, String> populateUsersHashMap;
|
| List columns;
|
| String [] headerColumns;
|
| String[] precheckedRoles;
| boolean isCheckboxesDisplay = false;
| HashMap ret ;
|
|
| Vector columnsVector;
|
|
| @In
| Identity identity;
|
|
| @Begin(join=true)
| public HashMap getPopulateUsers() {
|
| if (populateUsersHashMap == null) {
| Connection con = null;
| ResultSet rs = null;
| try {
| con = DriverManager.getConnection(url,
userName,password );
| CallableStatement cstmt =
con.prepareCall("{call usp_u_adm_select_UserList(?, ?)}");
| cstmt.setString(1,
searchStringFirstName);
| cstmt.setString(2,
searchStringLastName);
| rs = cstmt.executeQuery();
|
| populateUsersHashMap = new
HashMap<String, String>();
| count =0;
|
| while(rs.next()) {
|
populateUsersHashMap.put(rs.getString("Name"), rs.getString("UserID"));
| count = count + 1;
| }
| if (count==0){
| populateUsersHashMap.put("No
Users exist","No Users exist");
| }
| counter.put("counterkey",
Integer.toString(count));
| isDisplay = true;
| }
| catch(Exception e) {
| e.printStackTrace();
| }
| finally {
| try {
| rs.close();
| con.close();
| }
| catch(SQLException e) {
| e.printStackTrace();
| }
| }
| }
| return populateUsersHashMap;
| }
|
| public void processValueChange(ValueChangeEvent value) throws
AbortProcessingException {
|
selectedUserId.put("selecteduserid",(String)value.getNewValue());
| selectedUserId.put("selecteduserid","1504"); // Michael Bell
|
| displayRolesListForUser();
| // displayArbiStuff();
| isDisplay = true;
| isCheckboxesDisplay = true;
| }
|
| public void adminRoleChanged(ValueChangeEvent value) throws
AbortProcessingException {
| log.info("Testing adminRoleChanged
"+(String)value.getNewValue());
| }
|
| public void displayRolesListForUser() {
| log.info("Inside displayRolesListForUser");
| log.info("EXECUTING the Stored Procedure for UserID =
"+selectedUserId.get("selecteduserid").toString());
|
| columns = new ArrayList();
| Connection con = null;
| ResultSet rs = null;
|
|
| otherUserRolesStrArr = new ArrayList();
| otherUserRolesHashMap = new HashMap();
|
| adminUserRolesStrArr = new String[50];
| adminUserRolesHashMap = new HashMap();
|
| defaultUserRolesStrArr = new String[50];
| defaultUserRolesHashMap = new HashMap();
|
|
|
| columnsVector = new Vector();
|
| try {
| con =
DriverManager.getConnection(url, userName,password );
| CallableStatement cstmt =
con.prepareCall("{call usp_u_adm_select_UserRole(?)}");
|
| cstmt.setString(1,
selectedUserId.get("selecteduserid").toString());
| rs
= cstmt.executeQuery();
| int index=0;
| ResultSetMetaData rsmd = null;
|
| if (rs != null)
| {
| rsmd = rs.getMetaData();
| int totalColumnCount =
rsmd.getColumnCount();
| headerColumns = new
String[totalColumnCount];
| log.info("Total Column
Count = "+totalColumnCount);
| int j = 0;
| while (rs.next())
| {
|
| if
(rs.getString("IsChecked").equals("1"))
| {
|
log.info("ISCHECKED ==> 1");
|
log.info(rs.getString("ApplicationRoleID") + " "+ rs.getString("Name") + "
"+rs.getString("IsDefault") + " "+rs.getString("IsChecked"));
|
adminUserRolesStrArr[index] = rs.getString("ApplicationRoleID");
|
adminUserRolesHashMap.put(rs.getString("Name"),
rs.getString("ApplicationRoleID"));
|
log.info("===========================");
| }
|
| else if
(rs.getString("IsDefault").equals("1")){
|
log.info("ISDEFAULT ==> 1");
|
log.info(rs.getString("ApplicationRoleID") + " "+ rs.getString("Name") + "
"+rs.getString("IsDefault") + " "+rs.getString("IsChecked"));
|
defaultUserRolesStrArr[index] = rs.getString("ApplicationRoleID");
|
defaultUserRolesHashMap.put(rs.getString("Name"),
rs.getString("ApplicationRoleID"));
|
log.info("===========================");
| }
| else if( !(
rs.getString("IsChecked").equalsIgnoreCase("1") ||
|
rs.getString("IsDefault").equalsIgnoreCase("1") ))
| {
|
log.info("NOT isDefault OR isChecked TESTING....");
|
log.info(rs.getString("ApplicationRoleID") + " "+ rs.getString("Name") + "
"+rs.getString("IsDefault") + " "+rs.getString("IsChecked"));
|
otherUserRolesStrArr[index] = "false";//rs.getString("ApplicationRoleID");
|
otherUserRolesHashMap.put(rs.getString("Name"),
rs.getString("ApplicationRoleID"));
|
| }
| index = index+1;
| }
| }
| }
| catch(Exception e) {
| e.printStackTrace();
| }
| finally {
| try {
| rs.close();
| con.close();
| }
| catch(SQLException e) {
| e.printStackTrace();
| }
| }
| }
|
| @End
| public void submitSelection(){
| log.info("Inside submitSelection=========>CLICKED Submit");
|
| Connection con = null;
| ResultSet rs = null;
| String appRoleIDString = "";
| String xmlParam = "";
| String userId = "";
| String submittedByNetworkLogin = "";
| String submittedByUserId = "";
| String [] masterListUserRoles = null;
|
| userId = identity.getUsername();
|
|
| if (this.adminUserRolesStrArr != null &&
this.defaultUserRolesStrArr != null && this.otherUserRolesStrArr != null){
|
| int masterRoleCount = adminUserRolesStrArr.length +
defaultUserRolesStrArr.length + otherUserRolesStrArr.length;
|
| masterListUserRoles = new String[masterRoleCount];
|
| //masterListUserRoles = adminUserRolesStrArr +
defaultUserRolesStrArr + otherUserRolesStrArr;
| }
|
| if (masterListUserRoles != null)
| {
| log.info("The Selected Checkboxes are = ");
|
| for(int i=0; i<masterListUserRoles.length;i++)
| {
| log.info("masterListUserRoles
="+masterListUserRoles);
|
| appRoleIDString += "<ApplicationRole
ApplicationRoleID=\""+masterListUserRoles+"\" />";
| }
| log.info("appRoleIDString = " +
appRoleIDString);
| }
| xmlParam = "<?xml version=\"1.0\"
standalone=\"yes\"?><root>" + appRoleIDString + "</root>";
| log.info("in viewRoles: xmlParam = " + xmlParam);
|
| /*try {
| con = DriverManager.getConnection(url,
userName,password );
| CallableStatement cstmt = con.prepareCall("{call
usp_u_adm_update_UserRoleRecord(?,?,?,?)}");
|
| userId =
selectedUserId.get("selecteduserid").toString();
|
| cstmt.setString(1, userId);
| cstmt.setString(2, xmlParam);
| cstmt.setString(3, submittedByNetworkLogin);
| cstmt.setString(4, submittedByUserId);
|
| rs = cstmt.executeQuery();
| }
| catch(Exception e) {
| e.printStackTrace();
| }
| finally
| {
| try
| {
| rs.close();
| con.close();
| }
| catch(SQLException e) {
| e.printStackTrace();
| }
| } */
|
|
| }
|
| // ===============START : CHECKBOXES====================================
|
| public String[] getDefaultUserRolesStrArr() {
| return defaultUserRolesStrArr;
| }
|
| public void setDefaultUserRolesStrArr(String[] defaultUserRolesStrArr) {
| this.defaultUserRolesStrArr = defaultUserRolesStrArr;
| }
|
| public HashMap getDefaultUserRolesHashMap() {
| return defaultUserRolesHashMap;
| }
|
| public void setDefaultUserRolesHashMap(HashMap defaultUserRolesHashMap)
{
| this.defaultUserRolesHashMap = defaultUserRolesHashMap;
| }
|
| public String[] getAdminUserRolesStrArr() {
| return adminUserRolesStrArr;
| }
|
| public void setAdminUserRolesStrArr(String[] adminUserRolesStrArr) {
| this.adminUserRolesStrArr = adminUserRolesStrArr;
| }
|
| public HashMap getAdminUserRolesHashMap() {
| return adminUserRolesHashMap;
| }
|
| public void setAdminUserRolesHashMap(HashMap adminUserRolesHashMap) {
| this.adminUserRolesHashMap = adminUserRolesHashMap;
| }
|
| public HashMap getOtherUserRolesHashMap() {
| return otherUserRolesHashMap;
| }
|
|
| public void setOtherUserRolesHashMap(HashMap otherUserRolesHashMap) {
| this.otherUserRolesHashMap = otherUserRolesHashMap;
| }
|
| public String[] getOtherUserRolesStrArr() {
| log.info("Inside getOtherUserRolesStrArr");
| return otherUserRolesStrArr;
| }
|
|
| public void setOtherUserRolesStrArr(String[] otherUserRolesStrArr) {
| log.info("Inside setOtherUserRolesStrArr");
| if (otherUserRolesStrArr != null)
| {
| log.info("The Selected Checkboxes are = ");
| for(int i=0; i<otherUserRolesStrArr.length;i++)
| {
| log.info(otherUserRolesStrArr);
| }
| }
| this.otherUserRolesStrArr = otherUserRolesStrArr;
| }
|
|
| //===============END : CHECKBOXES====================================
|
|
| //===============START: DISPLAY COLUMN HEADERS
HORIZONTALLY======================
| public List<SelectItem> getColumns() {
| return columns;
| }
|
| public void setColumns(List<SelectItem> columns) {
| this.columns = columns;
| }
|
|
| public Vector getColumnsVector() {
| return columnsVector;
| }
|
|
| public void setColumnsVector(Vector columnsVector) {
| this.columnsVector = columnsVector;
| }
|
| public String[] getHeaderColumns() {
| return headerColumns;
| }
|
|
| public void setHeaderColumns(String[] headerColumns) {
| // this.headerColumns = headerColumns;
| }
|
| // ===============END: DISPLAY COLUMN HEADERS
HORIZONTALLY======================
|
| public String getSearchStringFirstName() {
| return searchStringFirstName;
| }
|
| public void setSearchStringFirstName(String searchStringFirstName)
{
| this.searchStringFirstName = searchStringFirstName;
| }
|
| public String getSearchStringLastName() {
| return searchStringLastName;
| }
|
| public void setSearchStringLastName(String
searchStringLastName) {
| this.searchStringLastName = searchStringLastName;
| }
|
| public boolean getIsDisplay(){
| return isDisplay;
| }
|
|
| public boolean getIsCheckboxesDisplay(){
| return isCheckboxesDisplay;
| }
|
| public String getSelName() {
| return selName;
| }
|
| public void setSelName(String selName) {
| this.selName = selName;
| }
|
| @Remove @Destroy
| public void destroy(){
|
| log.info("Inside destroy ============>");
| }
|
|
| public void displayArbiStuff() {
| log.info("Inside displayArbiStuff");
| String [] roleID = {"1","2"};
|
| String appRoleIDString = "";
| for (int i=0;i<roleID.length;i++)
| {
| appRoleIDString += "<ApplicationRole
ApplicationRoleID=\""+roleID+"\" />";
| }
| log.info("appRoleIDString = " + appRoleIDString);
| String xmlParam = "<?xml version=\"1.0\"
standalone=\"yes\"?><root>" + appRoleIDString + "</root>";
| log.info("in viewRoles: xmlParam = " + xmlParam);
|
| Connection con = null;
| ResultSet rs = null;
|
| HashMap cols = null;
| HashMap rows = null;
|
| ArrayList columnList = new ArrayList();
| ArrayList rowList = new ArrayList();
|
| int j = 0;
|
|
| try {
| con = DriverManager.getConnection(url,
userName,password );
| CallableStatement cstmt =
con.prepareCall("{call usp_u_adm_select_ViewUserRole(?)}");
| cstmt.setString(1, xmlParam);
| rs = cstmt.executeQuery();
| ResultSetMetaData rsmd = null;
| if (rs != null)
| {
| rsmd = rs.getMetaData();
| int totalColumnCount =
rsmd.getColumnCount();
| int k = 1;
| log.info("Column Names are :");
|
log.info("===============================================");
| while (rs.next())
| {
| j = j+1;
| for (int i = 1;
i<=totalColumnCount;i++)
| {
| cols = new
HashMap();
| if (i ==
totalColumnCount)
| {
|
log.info(rsmd.getColumnName(i));
|
cols.put(i, rsmd.getColumnName(i));
| }
| rows = new
HashMap();
|
log.info(rs.getString(i));
| rows.put(j,
rs.getString(i));
|
| }
|
log.info("===============================================");
| }
| columnList.add(cols);
| rowList.add(rows);
|
| log.info("Total Columns =
"+columnList.size());
| log.info("Total Rows =
"+rowList.size());
|
| }
| }
| catch(Exception e) {
| e.printStackTrace();
| }
| finally {
| try {
| rs.close();
| con.close();
| }
| catch(SQLException e) {
| e.printStackTrace();
| }
| }
| }
| }
|
|
|
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4083682#4083682
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4083682
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user