Results 1 to 2 of 2

Thread: Java Beans created over and over again

  1. #1
    Join Date
    Feb 2007
    Posts
    143

    Default Java Beans created over and over again

    Hi,

    have the confg.xml as follows

    Code:
    	<bean id="applicationBean"
    		class="com.framework.view.common.bean.ApplicationBean"
    		scope="session" >
    	</bean>
    As this is in session, should this not be created only once for a user/session?
    I have more than one object of this being created

    My ApplicationBean is as follows
    Code:
    public class ApplicationBean extends BaseBean {
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 4238807744322271127L;
    	private String appTitle;
    	@SuppressWarnings("unused")
    	private String pageTitle;
    	@SuppressWarnings("unused")
    	private String currentPage="login.faces";
    	// the logger for this class
    	private Log logger = LogFactory.getLog(this.getClass());
    	HtmlInputHidden title;
    	HtmlInputHidden searchString;
    	
    	
    
    	/**
    	 * Default Constructor.
    	 * 
    	 * @throws FacesException
    	 *             If internal error occurs while retrieves categories
    	 */
    	public ApplicationBean() {
    		super();
    		this.logger.debug("ApplicationBean is created");
    		
    	}
    
    
    
    
    	public String getAppTitle() {
    		return appTitle;
    	}
    
    
    
    
    	public void setAppTitle(String appTitle) {
    		this.appTitle = appTitle;
    	}
    
    
    
    
    	public String getPageTitle() {
    		return title.getValue().toString();
    	}
    	
    	public  String getStrSearch(){
    		return searchString.getValue().toString();
    	}
    
    
    
    
    	public void setPageTitle(String pageTitle) {
    		this.pageTitle = pageTitle;
    	}
    
    
    
    
    	public HtmlInputHidden getTitle() {
    		return title;
    	}
    
    
    	public void setTitle(HtmlInputHidden title) {
    		this.title = title;
    	}
    
    
    
    
    	public HtmlInputHidden getSearchString() {
    		return searchString;
    	}
    
    
    
    
    	public void setSearchString(HtmlInputHidden searchString) {
    		this.searchString = searchString;
    	}
    
    
    	
    
    	
    }
    The BaseBean extends ConObject
    Base Bean is as follows
    Code:
    public  class BaseBean extends ConObject implements IBaseBean, Serializable {
    
    	/**
    	 * This bean is the parent of all view beans that represent a model object
    	 */
    	private static final long serialVersionUID = -172442932994218985L;
    	/**
    	 * When a row is changed in an updatable
    	 * grid this value is stored in the change row field
    	 */
    	public static final  String CHANGE="CHANGE";
    	/**
    	 * When a row is inserted into an updatable
    	 * grid this value is stored in the change row field
    	 */
    	public static final  String NEW="NEW";
    	/**
    	 * When a row is marked for delete in an updatable
    	 * grid this value is stored in the change row field
    	 */
    	public static final  String DELETE="DELETE";
    
    	
    	/**
    	 * This is the property for the heading select box
    	 */
    	protected boolean selectAll = false;
    	/**
    	 * This is the select box on each row
    	 */
    	protected boolean rowsSelect = false;
    	/**
    	 * This field stores the row status CHANGE NEW DELETE and "" 
    	 * when no changes have occurred 
    	 * the default value =""
    	 */
    	private String changeRow="";
    	
    	
    	public Boolean[] viewed={false,false,false,false,false};
    	protected boolean showToggle=false;
    	public List<String> valErrorList;
    	public String scratchPad;
    	
    	public BaseBean() {
    			init();
    	
    	}
    	
    
    
    
    	protected void init() {
    	}
    
    
    	public void runInit() {
    		this.init();
    	}
    	
    	
    }
    ConObject is
    Code:
    public class ConObject {
    	protected static JdbcLogError execLogError;
    	protected Date today = AppUtils.getSysdate();
    	protected String executionTime;
    	protected FacesContext fc;
    	protected ExternalContext ctx;
    	protected String message;
    	protected String statusMessage;
    	protected boolean showMessage;
    	protected final Log logger = LogFactory.getLog(this.getClass());
    	protected Date now=new Date();
    	protected String returnPath;
    	protected ServletContext context;
    	protected ApplicationContext appContext;
    	private boolean collapsed;
    
    	
    	protected String returnAction;
    	
    	public ConObject() {
    		super();
    		fc = FacesContext.getCurrentInstance();
    		ctx = fc.getExternalContext();
    		context = FacesUtils.getServletContext();
        	appContext= WebApplicationContextUtils.getRequiredWebApplicationContext(context);
        
    	
    	}
    
    	
    	
    
    	
    	public ApplicationContext getAppCtx() {
    		ServletContext context = FacesUtils.getServletContext();
    		return WebApplicationContextUtils
    				.getRequiredWebApplicationContext(context);
    	}
    
    
    
    
    }
    Is there any issue with this?

    Thanks
    Vinaya

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    I suggest the reference guide. Simply slapping scope="session" on there isn't going to be enough, you will also have to include the <aop:scoped-proxy />.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •