banco.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Departamento Pessoal</title>
<link type="text/css" href="${facesContext.externalContext.requestContextPath}/estilo.css" rel="stylesheet"/>
<f:loadBundle basename="depto.aop.propriedades.rotulos" var="msgs"/>
<title><h:outputText value="#{msgs.banco}"/></title>
</h:head>
<h:body>
<f:view contentType="text/html">
<div id="menu">
<ui:include src="/menu.xhtml" />
</div>
<div id="pagina">
<h1 align="center"><h:outputText>#{AOP.message("banco")}</h:outputText></h1>
<br />
<h:form>
<h:panelGrid columns="2" border="1">
<h:panelGroup>
<h:outputLabel value="Código" class="rotulo"/>
</h:panelGroup>
<h:panelGroup>
<h:inputText id="codigo" value="1"/>
<h:message for="codigo" />
</h:panelGroup>
<h:panelGroup>
<h:outputLabel value="Banco" class="rotulo"/>
</h:panelGroup>
<h:panelGroup>
<h:inputText id="banco" value="Banco do Brasil" />
<h:message for="banco" />
</h:panelGroup>
<f:facet name="footer">
<ui:include src="/botoes/cadastro.xhtml" />
</f:facet>
</h:panelGrid>
</h:form>
</div>
</f:view>
</h:body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config version="2.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
<managed-bean>
<managed-bean-name>depto.usuario</managed-bean-name>
<managed-bean-class>depto.usuario.usuario</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<resource-bundle>
<base-name>depto.aop.propriedades.rotulos</base-name>
<var>msgs</var>
<locale-config>
<default-locale>pt_BR</default-locale>
<supported-locale>en_US</supported-locale>
</locale-config>
</resource-bundle>
</faces-config>
AOP.JAVA
package depto.aop;
import java.util.Locale;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
@ManagedBean(name = "AOP")
@ViewScoped
public class AOP {
private static ApplicationContext context;
private static AOP instancia;
private static SessionFactory sessionFactory;
private static Locale local = Locale.getDefault();
public synchronized static Object getBean(final String nome) {
final ApplicationContext context = AOP.getContext();
if (context != null) {
try {
return context.getBean(nome);
} catch (final Exception e) {
e.printStackTrace();
return null;
}
}
return null;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static synchronized Object getBean(final String nome,
final Class classe) {
final ApplicationContext context = AOP.getContext();
if (context != null) {
try {
return context.getBean(nome, classe);
} catch (final Exception e) {
e.printStackTrace();
return null;
}
}
return null;
}
public static ApplicationContext getContext() {
try {
if (AOP.context == null) {
AOP.context = new ClassPathXmlApplicationContext(
"depto/aop/spring.xml");
}
} catch (Exception e) {
e.printStackTrace();
}
return AOP.context;
}
public static synchronized AOP getInstancia() {
return (AOP.instancia == null) ? new AOP() : AOP.instancia;
}
public static synchronized String getMessage(final String string) {
return AOP.getContext().getMessage(string, null, AOP.local);
}
public static Session getSession() {
final Session session = SessionFactoryUtils.getSession(
AOP.sessionFactory, true);
return session;
}
DataIntegrityViolationException DataIntegrityViolationException(
final String msg) {
return DataIntegrityViolationException(msg);
}
public static Locale getLocal() {
return local;
}
public static void setLocal(Locale local) {
AOP.local = local;
System.out.println(AOP.local);
}
}
spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- ***************************************************************************************************
Configuração AOP: spring framework
**************************************************************************************************** -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.query.substitutions">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>depto/usuario/Usuario.hbm.xml</value>
</list>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:file:/hsqldb/db_cacthus"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- ***************************************************************************************************
Configuração AOP: properties
**************************************************************************************************** -->
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>depto.aop.propriedades.rotulos</value>
</list>
</property>
</bean>
<!-- ***************************************************************************************************
package: depto.usuario.Usuario
**************************************************************************************************** -->
<bean id="usuario-imp" class="depto.usuario.UsuarioImp">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
</beans>