论坛首页 Java企业应用论坛

wicket1.3.5+spring2.5+hibernate3.2

浏览 4167 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-10-28  
   不喜欢Tapestry4要用hivemind,wicket与spring集成更简单些,刚接触wicket,学习下。
1.web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
	xmlns="http://java.sun.com/xml/ns/j2ee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	
	<display-name>wicket</display-name>
	
	<listener>    
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    
	</listener>
	
	<context-param>    
		<param-name>contextConfigLocation</param-name>    
		<param-value>classpath:applicationContext.xml</param-value>    
	</context-param>  
	
    <servlet>
	    <servlet-name>wicket</servlet-name>
	    <servlet-class>org.apache.wicket.protocol.http.WicketServlet</servlet-class>
	    <init-param>
	        <param-name>applicationFactoryClassName</param-name>
	        <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
	    </init-param>
	    <load-on-startup>1</load-on-startup>
	</servlet>
    <servlet-mapping>
		<servlet-name>wicket</servlet-name>
		<url-pattern>/*</url-pattern>
	</servlet-mapping>
    
</web-app>


2.applicationContext.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"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
	<description>Wicket</description>
	<!-- dataSource for Oracle -->
	<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName"
			value="com.mysql.jdbc.Driver"/>
		<property name="url"
			value="jdbc:mysql://localhost:3306/wicket" />
		<property name="username" value="logcd" />
		<property name="password" value="****" />
	</bean>

	<!-- Hibernate SessionFactory for mysql -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />

		<property name="mappingDirectoryLocations">
			<list>
				<value>classpath:com/logcd/wicket/mapping/</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.MySQLDialect
				</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.jdbc.fetch_size">50</prop>
				<prop key="hibernate.jdbc.batch_size">100</prop>
			</props>
		</property>
	</bean>
	<!-- Hibernate SessionFactory for mysql -->

	<!-- Transaction -->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<bean id="baseTransactionProxy" lazy-init="true" abstract="true"
		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
		<property name="transactionManager" ref="transactionManager" />
		<property name="transactionAttributes">
			<props>
				<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="save*">PROPAGATION_REQUIRED</prop>
				<prop key="do*">PROPAGATION_REQUIRED</prop>
				<prop key="update*">PROPAGATION_REQUIRED</prop>
				<prop key="delete*">PROPAGATION_REQUIRED</prop>
			</props>
		</property>
	</bean>
	<!-- Transaction -->

	<!-- DAO -->
	<bean id="baseDao" lazy-init="true" abstract="true"
		class="com.logcd.common.bo.dao.impl.GenericDaoImpl">
		<property name="sessionFactory">
			<ref local="sessionFactory" />
		</property>
	</bean>
	
	<bean id="kingModulesDao" parent="baseDao" 
		class="com.logcd.web.bo.dao.impl.KingModulesDaoImpl">
	</bean>
	<!-- DAO -->

	<!--service-->
	<bean id="publicService" parent="baseTransactionProxy"> 
		<property name="target"> 
			<bean class="com.logcd.web.business.service.impl.PublicServiceImpl" autowire="byName"> 
			</bean> 
		</property> 
	</bean>
	<!--service-->
	<bean id="wicketApplication" class="com.logcd.wicket.lab.WicketApplication"/>

</beans>


3.WicketApplication.java
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;

import com.logcd.wicket.index.Index;

public class WicketApplication extends WebApplication {

	public WicketApplication() {
	}

	public void init() {
		super.init();
		addComponentInstantiationListener(new SpringComponentInjector(this));    
	}

	public Class getHomePage() {
		return Index.class;
	}
}

4.页面java中注入bean:类型不能为接口,用private  PublicService publicService要报错。
	@SpringBean(name="publicService")
	private PublicServiceImpl publicService;



附:wicketAjaxDebugEnable=false;//禁用Ajax调试
   Wicket 与通常的Web 程序有一点不同,就是它的运行状态分成开发模式(Development Mode)和部署模式(Deploy Mode)。
(1).web.xml
<param-name>configuration</param-name>
<param-value>DEPLOYMENT</param-value>

(2).是调用Application 这个基类中的configure 方法来改变当前的运行状态。
webApplica tion.configure(Application.DEVELOPMENT);
webApplica tion.configure(Application.DEPLOYMENT);
   发表时间:2008-10-28  
tapestry5 跟方便, 可以把spring的bean想tapestry ioc一样注入。
0 请登录后投票
   发表时间:2008-10-29  
t5与spring的集成是比t4好多了,不过组件不及现在的wicket丰富
0 请登录后投票
   发表时间:2009-01-08  
wicket设计很不错。

一看就让我想起swing
0 请登录后投票
   发表时间:2009-01-09   最后修改:2009-01-09
想起TSS上面关于T5的讨论,有一个有意思的话题就是
有人说T5的变化太大,完全不兼容
Tapestry的作者Howard Lewis Ship就回复说T5是一个开创性版本,以后会兼容的
结果楼下的兄弟不给面子,回了一句说:T4的时候也是这么说的

不知道Howard Lewis Ship会不会脸红啊。

原文如下:

Posted by: Jan de Jonge on ??? 19, 2008 in response to Message #285856
引用
T5 is built for backwards compatibility; Tapestry prior was not.


Howard,

This is exactly what you said when you were re-writing Tapestry for T4.
0 请登录后投票
   发表时间:2009-01-18  
我本来使用 Tapestry 的,当时是4.0版本,结果5.0出来了,变化真大啊,那时才明白,微软为什么是一家伟大的公司。

现在改投 Wicket 了,希望不要想Tapeatry那样。

顺便说一下,像TAPESTRY这样的软件,哪个公司敢使用啊?
0 请登录后投票
   发表时间:2009-02-16  
代码共享下呢
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics