[jboss-cvs] jbosstest/src/jdk15/org/jboss/test/jsf/webapp ...
Stan Silvert
ssilvert at jboss.com
Wed Jul 19 17:28:44 EDT 2006
User: ssilvert
Date: 06/07/19 17:28:44
Added: src/jdk15/org/jboss/test/jsf/webapp InjectionBean.java
MySessionBean.java
Log:
Updated JSF and JSTL version. Added test for JSF and JSTL integration.
Revision Changes Path
1.1 date: 2006/07/19 21:28:44; author: ssilvert; state: Exp;jbosstest/src/jdk15/org/jboss/test/jsf/webapp/InjectionBean.java
Index: InjectionBean.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.jsf.webapp;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.context.FacesContext;
import javax.naming.InitialContext;
import javax.sql.DataSource;
/**
* Tests resource injection and lifecycle annotations for JSF managed bean.
*
* @author Stan Silvert
*/
public class InjectionBean {
private DataSource defaultDS;
private boolean postConstructCalled = false;
private boolean datasourceInjected = false;
// This bean lives in the HttpSession. Save a reference here.
private MySessionBean mySessionBean = null;
/** Creates a new instance of InjectionBean */
public InjectionBean() {
}
public String getName() {
return "InjectionBean";
}
public boolean getPostConstructCalled() {
return this.postConstructCalled;
}
public boolean getDatasourceInjected() {
return this.datasourceInjected;
}
@PostConstruct
public void testPostConstruct() {
this.postConstructCalled = true;
Object dataSourceFromLookup = null;
try {
dataSourceFromLookup = new InitialContext().lookup("java:/DefaultDS");
} catch (Exception e) {
e.printStackTrace();
}
if (defaultDS == dataSourceFromLookup) {
this.datasourceInjected = true;
}
// doing this puts an instance of MySesisonBean into the session
ValueExpression preDestroyVe = expressionFactory().createValueExpression(elContext(), "#{mySessionBean}", MySessionBean.class);
this.mySessionBean = (MySessionBean)preDestroyVe.getValue(elContext());
}
private ELContext elContext() {
return FacesContext.getCurrentInstance().getELContext();
}
private ExpressionFactory expressionFactory() {
return FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
}
@PreDestroy
public void testPreDestroy() {
this.mySessionBean.setPreDestroyCalled(true);
}
@Resource(name="java:/DefaultDS")
public void setDefaultDS(DataSource dataSource) {
this.defaultDS = dataSource;
}
}
1.1 date: 2006/07/19 21:28:44; author: ssilvert; state: Exp;jbosstest/src/jdk15/org/jboss/test/jsf/webapp/MySessionBean.java
Index: MySessionBean.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.jsf.webapp;
/**
* Session bean used to tell if @PreDestroy was called on the InjectionBean.
*
* Also allows you to get the numList for testing JSTL/JSF integration.
*
* @author Stan Silvert
*/
public class MySessionBean {
private String[] numList = {"number one", "number two", "number three"};
private boolean preDestroyCalled = false;
public boolean isPreDestroyCalled() {
return this.preDestroyCalled;
}
public void setPreDestroyCalled(boolean preDestroyCalled) {
this.preDestroyCalled = preDestroyCalled;
}
public String[] getNumList() {
return this.numList;
}
public void setNumList(String[] numList) {
this.numList = numList;
}
}
More information about the jboss-cvs-commits
mailing list