[jboss-user] [JBoss Seam] - Need help with <h:selectOneMenu> and valueChangeListener met

asookazian do-not-reply at jboss.com
Fri Aug 31 14:44:46 EDT 2007


Using JBoss 4.0.5 and Seam 1.2.1.GA.

In the below .xhtml file, the valueChangeListener="#{userRoleSearch.processValueChange}" does not fire the public processValueChange method in my SFSB when the commented <s:div> and </s:div> tags around it are uncommented.  It does execute when the tags are commented.  In either case, the drop-down is rendered.

Why does this happen?  I experienced the same thing with the <s:fragment> tag.  Any help would be greatly appreciated...


  | 
  | <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  |                       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  |                       
  | 
  |                       
  | <ui:composition xmlns="http://www.w3.org/1999/xhtml"
  |                 xmlns:s="http://jboss.com/products/seam/taglib"
  |                 xmlns:ui="http://java.sun.com/jsf/facelets"
  |                 xmlns:f="http://java.sun.com/jsf/core"
  |                 xmlns:h="http://java.sun.com/jsf/html"
  |                 xmlns:rich="http://richfaces.ajax4jsf.org/rich"
  |                 template="layout/template.xhtml">
  |                 
  |                
  | 
  | <ui:define name="body">
  | 
  |     <h:messages globalOnly="true" styleClass="message"/>
  |     
  |     <rich:panel>
  |     
  | 	    <h:form>
  | 	    	<h:outputText id="userRoleInfo" value="User-Role Information"/><br/>
  | 	    	<h:outputText id="firstName" value="First Name:"/>
  | 	    	<h:outputText id="lastName" value="Last Name:"/><br/>
  | 	    	<h:inputText id="inputFirstName" value="#{userRoleSearch.searchStringFirstName}"/>
  | 	    	<h:inputText id="inputLastName" value="#{userRoleSearch.searchStringLastName}"/>    
  | 	    	
  | 	    	<h:commandButton id="searchButton" value="Search" action="#{userRoleSearch.getUsers}"/>
  | 	    	<h:commandButton id="resetButton" value="Reset" type="reset"/><br/><br/>
  | 	    	
  | 	    	<h:outputText value="No Users Found" rendered="#{userRoleSearch.isDisplay and userRoleSearch.rowCount==0}"/>
  | 	    	    
  | 	       <!-- <s:div id="selectUserDD" rendered="#{userRoleSearch.isDisplay and userRoleSearch.rowCount>0}"> -->
  | 	       	        
  | 			    	<h:outputText value="Select a user:"/>
  | 			    	
  | 			    	<h:selectOneMenu id="userFnameLname" valueChangeListener="#{userRoleSearch.processValueChange}" onchange="submit()">
  | 			            <f:selectItems value="#{userRoleSearch.populateUsers}"/>  
  | 			        </h:selectOneMenu><br/><br/>
  | 			
  | 			<!-- </s:div>  -->
  | 			        
  | 			
  | 	        <s:div id="selectRoleCheckBox" rendered="#{!empty userRoleSearch.currentUserId}"> 
  | 		        <h:selectManyCheckbox id="userRoles">
  | 		        	<f:selectItems value="#{userRoleSearch.userRoles}"/>	
  | 		        </h:selectManyCheckbox>
  | 		    </s:div>
  | 	     	
  | 	        
  | 	        <s:link id="viewUserRoleSummary" value="View User-Role Summary" view="/filterRoles.xhtml"/>
  | 	           	
  | 	    	
  | 	    </h:form>  
  |     
  |     </rich:panel>
  |     
  |     
  | </ui:define> 
  | </ui:composition>

SFSB:

package com.cox.beans.session;
  | 
  | import java.sql.CallableStatement;
  | import java.sql.Connection;
  | import java.sql.DriverManager;
  | import java.sql.ResultSet;
  | import java.sql.SQLException;
  | import java.util.ArrayList;
  | import java.util.HashMap;
  | import java.util.List;
  | 
  | import javax.ejb.Remove;
  | import javax.ejb.Stateful;
  | import javax.faces.context.FacesContext;
  | import javax.faces.event.ValueChangeEvent;
  | 
  | import org.apache.log4j.Logger;
  | import org.jboss.seam.annotations.Destroy;
  | import org.jboss.seam.annotations.In;
  | import org.jboss.seam.annotations.Name;
  | 
  | @Stateful
  | @Name("userRoleSearch")
  | public class UserRoleSearchSFSB implements UserRoleSearchSFSBLocal {
  | 	
  | 	private String searchStringFirstName = "";
  | 	private String searchStringLastName = "";
  | 	private String currentUserId = "";
  | 	private boolean isDisplay = false; 
  | 	
  | 	private ResultSet rs = null;
  | 	private CallableStatement cstmt = null;
  | 	private Connection con = null;
  | 	private HashMap<String, String> hm = null;
  | 	private HashMap<String, String> hm2 = null;
  | 	
  | 	Logger log = Logger.getLogger(this.getClass());
  | 	
  | 	int rowCount = 0;
  | 	
  | 	public void getUsers() {
  | 								
  | 		log.info("getUsers(): searchStringFirstName = " + searchStringFirstName);
  | 		log.info("getUsers(): searchStringLastName = " + searchStringLastName);
  | 				
  | 		try {
  | 			String url = "jdbc:sqlserver://CORG0DV01:1433;databaseName=JavaTestDB";
  | 			con = DriverManager.getConnection(url, "_AppUser_JavaTestAcct", "JavaTestAcct");
  | 			cstmt = con.prepareCall("{call usp_u_adm_select_UserList(?, ?)}");
  | 			cstmt.setString(1, searchStringFirstName);
  | 			cstmt.setString(2, searchStringLastName);
  | 			rs = cstmt.executeQuery();
  | 						
  | 			log.info("rs.next() = " + rs.next());
  | 			
  | 			hm = new HashMap<String, String>();
  | 			
  | 			while(rs.next()) {
  | 				hm.put(rs.getString("UserID"), rs.getString("Name"));
  | 				
  | 				String name = rs.getString("Name");
  | 				log.info("getUsers(): name = " + name);
  | 
  | 				String UserID = rs.getString("UserID");
  | 				log.info("getUsers(): UserID = " + UserID);
  | 				
  | 				rowCount++;
  | 			}
  | 			log.debug("in getUsers: rowCount = " + rowCount);
  | 			
  | 		}
  | 		catch(Exception e) {
  | 			e.printStackTrace();			
  | 		}
  | 		finally {
  | 			this.cleanUp();
  | 		}
  | 		
  | 		//search button clicked so set isDisplay to false so <div> in adminUserRoles.xhtml can check for display purposes
  | 		isDisplay = true;
  | 		
  | 		
  | 		
  | 	}
  | 	
  | 	public HashMap getPopulateUsers() {
  | 				
  | 		log.info("getPopulateUsers(): searchStringFirstName = " + searchStringFirstName);
  | 		log.info("getPopulateUsers(): searchStringLastName = " + searchStringLastName);
  | 		
  | 		try {
  | 			
  | 			String url = "jdbc:sqlserver://CORG0DV01:1433;databaseName=JavaTestDB";
  | 			Connection con = DriverManager.getConnection(url, "_AppUser_JavaTestAcct", "JavaTestAcct");
  | 			
  | 			if (con == null) {
  | 				log.debug("con is null");
  | 			}
  | 			
  | 			cstmt = con.prepareCall("{call usp_u_adm_select_UserList(?, ?)}");
  | 			cstmt.setString(1, searchStringFirstName);
  | 			cstmt.setString(2, searchStringLastName);
  | 			rs = cstmt.executeQuery();
  | 			
  | 			log.debug("rs.getRow() = " + rs.getRow());
  | 			
  | 			hm = new HashMap<String, String>();
  | 			
  | 			while(rs.next()) {
  | 				hm.put(rs.getString("Name"), rs.getString("UserID"));
  | 				
  | 				String name = rs.getString("Name");
  | 				log.info("getPopulateUsers(): name = " + name);
  | 
  | 				String UserID = rs.getString("UserID");
  | 				log.info("getPopulateUsers(): UserID = " + UserID);
  | 								
  | 			}
  | 			
  | 		}
  | 		catch(Exception e) {
  | 			e.printStackTrace();			
  | 		}
  | 		finally {
  | 			this.cleanUp();			
  | 		}
  | 		
  | 		return hm;
  | 		
  | 	}
  | 	
  | 	public HashMap getUserRoles() {
  | 						
  | 		log.info("in getUserRoles()");
  | 				
  | 		if(hm2==null) {
  | 			log.info("damn thing is null");
  | 		}
  | 		return hm2;
  | 						
  | 	}
  | 		
  | 	public void processValueChange(ValueChangeEvent value) {
  | 		log.info("begin processValueChange()");
  | 		
  | 		currentUserId = (String)value.getNewValue();
  | 		log.info("processValueChange(): currentUserId = " + currentUserId);
  | 		
  | 		try {
  | 			
  | 			String url = "jdbc:sqlserver://CORG0DV01:1433;databaseName=JavaTestDB";
  | 			Connection con = DriverManager.getConnection(url, "_AppUser_JavaTestAcct", "JavaTestAcct");
  | 			
  | 			cstmt = con.prepareCall("{call usp_u_adm_select_UserRole(?)}");
  | 			cstmt.setString(1, currentUserId);			
  | 			rs = cstmt.executeQuery();
  | 			
  | 			hm2 = new HashMap<String, String>();
  | 			
  | 			while(rs.next()) {
  | 				hm2.put(rs.getString("Name"), rs.getString("IsChecked"));
  | 				
  | 				String name = rs.getString("Name");
  | 				log.info("getUserRoles(): name = " + name);
  | 
  | 				String isChecked = rs.getString("IsChecked");
  | 				log.info("getUserRoles(): IsChecked = " + isChecked);
  | 								
  | 			}
  | 			
  | 			log.info("processValueChange(): rowCount = " + rowCount);
  | 			
  | 		}
  | 		catch(Exception e) {
  | 			e.printStackTrace();			
  | 		}
  | 		finally {
  | 			this.cleanUp();
  | 		}
  | 		
  | 
  | 	}
  | 	
  | 	
  | 	public String getCurrentUserId() {
  | 		log.info("in getCurrentUserId: currentUserId = " + currentUserId);
  | 		return currentUserId;
  | 	}
  | 	
  | 	public void setCurrentUserId(String currentUserId) {
  | 		log.info("in setCurrentUserId: currentUserId = " + currentUserId);
  | 		this.currentUserId = currentUserId;
  | 	}
  | 	
  | 	public String getSearchStringFirstName() {
  | 	      return searchStringFirstName;
  | 	}
  | 	   
  |     public void setSearchStringFirstName(String searchStringFirstName) {  
  |     	log.info("in setSearchStringFirstName");
  |       this.searchStringFirstName = searchStringFirstName;
  |     }
  |     
  | 	public String getSearchStringLastName() {
  | 		return searchStringLastName;
  | 	}
  | 	
  | 	public void setSearchStringLastName(String searchStringLastName) {
  | 		log.info("in setSearchStringLastName");
  | 		this.searchStringLastName = searchStringLastName;
  | 	}
  | 	
  | 	public boolean getIsDisplay() {
  | 		log.info("in getIsDisplay: isDisplay = " + this.isDisplay);		
  | 		return this.isDisplay;
  | 	}
  | 	
  | 	public int getRowCount() {
  | 		log.info("in getRowCount: rowCount = " + rowCount);
  | 		
  | 		return rowCount;
  | 	}
  | 	
  | 	private void cleanUp() {
  | 		try {
  | 			if (rs != null) rs.close();
  | 			if (cstmt != null) cstmt.close();
  | 			if (con != null) con.close();
  | 		}
  | 		catch(SQLException e) {
  | 			e.printStackTrace();
  | 		}
  | 	}
  | 	
  | 	
  | 	@Remove @Destroy
  | 	public void destroy() {
  | 		log.info("destroy() called");
  | 	}
  | 	
  | 
  | }

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

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



More information about the jboss-user mailing list