xmlns:t=\
t:body用来定义什么地方来放置一个组件模板。
使用模板:
xmlns:t=\
Name
5.Spring integration 和Spring 集成
Wicket and Tapestry中集成spring都很简单,无缝集成。
wicket:
在init()加一行代码:
Java代码
addComponentInstantiationListener(new SpringComponentInjector(this));
类似这样:
public class WicketApplication extends WebApplication{ public WicketApplication(){}
public void init(){ super.init();
addComponentInstantiationListener(new SpringComponentInjector(this)); }
public Class
接下来就可以使用spring bean从page class中使用annotating @SpringBean调用:
public class AddMemberPage extends BasePage { private static final Logger logger =
LoggerFactory.getLogger(AddMemberPage.class);
private Member member;
private @SpringBean MemberService service;
public AddMemberPage() {
add(new AddMemberForm(\Member() ))); }
public class AddMemberForm extends Form {
public AddMemberForm(String id, final CompoundPropertyModel model) { super(id, model);
member = (Member)model.getObject();
add(new TextField(\
add(new Button(\ public void onSubmit(){
logger.info(\ service.add(member); } }); } } }
Tapestry 5
在Tapestry 5中,spring bean被看作tapestry 5的组件,无缝调用和通过tapestry 5 IoC注入。为了集成spring,你需要修改web.xml中一行:
接下来就能注入spring bean进入page class通过简单的@Inject annotation:
public class Add {
@Inject private Logger logger;
@Inject private MemberService service;
@Inject @Property @Parameter private Member member;
void onSelectedFromSave(){
logger.info(\
} }
6.Page unit testing
Wicket and Tapestry5的Page unit testing都不需要启动一个servlet容器。
wicket:
不需要锁定一个特殊测试框架,你可以使用JUnit或者TestNG都没问题,因为wicket提供helper class:
WicketTester来做page class的Unit testing:
public class TestHomePage extends TestCase {
private WicketTester tester;
@Override
public void setUp() {
tester = new WicketTester(new WicketApplication()); }
public void testRenderMyPage() {
//start and render the test page tester.startPage(HomePage.class);
//assert rendered page class
tester.assertRenderedPage(HomePage.class); } }
Tapestry 5
也不需要锁定一个特殊测试框架:
public class MyTest extends Assert {
@Test