Wicket Hello World Example
A simple hello world example in Wicket, show the basic structure of Wicket web application.
Tools and technologies used in this article
- Apache Wicket 1.4.17
- Eclipse 3.6
- Maven 3.0.3
- JDK 1.6.0.13
1. Directory Structure
See the final directory structure of this Wicket hello world web application. In Wicket, you need to put all files “.html
” and “.java
” in a same package directory.
See figure below :
Follow below steps to create the entire directory structure.
2. Maven Quick Start
Create a simple web application via Maven.
mvn archetype:generate -DgroupId=com.mkyong.core -DartifactId=WicketExamples
-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
Now, it will create all the standard web folder structure.
3. Wicket Dependency
Add Wicket dependency in your Maven pom.xml
file.
File : pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mkyong.core</groupId>
<artifactId>WicketExamples</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>WicketExamples</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket</artifactId>
<version>1.4.17</version>
</dependency>
<!-- slf4j-log4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
</dependencies>
<build>
<finalName>WicketExamples</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<filtering>false</filtering>
<directory>src/main/java</directory>
<includes>
<include>*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<optimise>true</optimise>
<debug>true</debug>
</configuration>
</plugin>
</plugins>
</build>
</project>
Wicket need SLF4J !
You have to include the slf4j logging implementation, otherwise Wicket will be failed to start.
Wicket need resource filter
Remember to add the resource
filter, Wicket puts all files in same package folder, if you didn’t define the resource filter to include everything “<include>*</include>
” , “html”, “properties” or other resources files may failed to copy to the correct target folder.
4. Wicket Applications
In Wicket, most stuffs are work by convention, you don’t need to configure it. In this case, WebApplication
returns a “Hello.class
” as the default page, when Wicket see this “Hello.class
“, it know the mark up “html
” page should be “Hello.html
“, and it should be able to find at the same package directory. This is why Wicket need you to put both “html” and “java” class together.
File : MyApplication.java – The main application entrance.
package com.mkyong;
import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;
import com.mkyong.hello.Hello;
public class MyApplication extends WebApplication {
@Override
public Class<? extends Page> getHomePage() {
return Hello.class; //return default page
}
}
File : Hello.java
package com.mkyong.hello;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.WebPage;
public class Hello extends WebPage {
private static final long serialVersionUID = 1L;
public Hello(final PageParameters parameters) {
add(new Label("message", "Hello World, Wicket"));
}
}
File : Hello.html
<html>
<head>
</head>
<body>
<h1>
<span wicket:id="message">message will be replace later</span>
</h1>
</body>
</html>
5. Wicket Filters
To make Wicket works, you need to register Wicket filters in your web.xml file.
File : web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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"
version="2.4">
<display-name>Wicket Web Application</display-name>
<filter>
<filter-name>wicket.wicketTest</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>com.mkyong.MyApplication</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>wicket.wicketTest</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
6. Build it
All files are ready, build it with Maven.
mvn eclipse:eclipse -Dwtpversion=2.0
Import it into Eclipse and start the project.
7. Test It
Visit http://localhost:8080/WicketExamples/ , see figure :
Done.
Wicket Hello World Example的更多相关文章
- wicket基本控件使用笔记
Label new Label(“message”,”message content”); MutLineLabel new MutlineLabel(“message”, ...
- wicket基础应用(3)——wicket控件的隐藏和显示
在一个项目,页面经常要显示和隐藏一些控件,用wicket来控制显示和隐藏控件相当的方便. 1.最简单的隐藏和显示方法: wicket的控件大部分都有setVisible(...)方法,用这个方法就可以 ...
- wicket基础应用(2)--wicket表单控件的使用
该文可以转载,但转载必须注明作者,出处: 作者:lhx1026 出处:http://lhx1026.iteye.com/ 这一章介绍wicket表单控件的简单应用 1.Label控件 这个应该说是最常 ...
- wicket基础应用(1)--使用wicket对表单中的数据进行验证
作者:lhx1026 出处:http://lhx1026.iteye.com/ wicket基础应用(1)--使用wicket对表单中的数据进行验证 举个例子: 1.有一个Java文件SysCharg ...
- 使用maven在netbeans下构建wicket项目
在netbeans下构建wicket项目,网上流传较多的方法是直接使用netbeans的wicket插件,这种方法虽然简单,但是依赖的wicket版本较老,更新较慢,并且很容易与其他第三方库不兼容.使 ...
- netbeans中wicket插件对应的jQuery-ui版本
在netbean里使用wicket,我们经常习惯使用netbeans自带的wicket插件直接安装wicket,但是因为netbean上的 wicket插件版本比较老,使得我们很多新的第三方wicke ...
- How to setup Wicket Examples in Eclipse
Wicket examples is a good place to learn Apache Wicket by examples, and a must reference site for ne ...
- apache开源项目 -- Wicket
[infoq] Apache Wicket是一个功能强大.基于组件的轻量级Web应用框架,能将展现和业务逻辑很好地分离开来.你能用它创建易于测试.调试和支持的高质量Web 2.0应用.假设其他团队交付 ...
- Meet Apache Wicket
第一次接触Wicket,如此多的内容是文字,的原贴,希望大家指正 Meet Apache Wicket By JonathanLocke, original author of Wicket 乔纳森· ...
随机推荐
- file类型允许的文件格式设置问题,“选择文件”打开缓慢
1,file类型的input对于打开的选择框的属性是由以下两个属性控制的: ①multiple="multiple" :一次可以选择多个文件 ②accept="image ...
- 你其实真的不懂print("Hello,world")
http://www.jianshu.com/p/abb55919c453 debugPrint在发布的版本里也 会输出debugPrint只是更倾向于输出对象的调试信息.不管是开发环境还是测试环境都 ...
- UIScrollView 期本使用方法
UIScrollView 1. contentOffset 默认CGPointZero,用来设置scrollView的滚动偏移量. // 设置scrollView的滚动偏移量 scrollView ...
- hadoop NameNode 实现分析
在hadoop 整体分析中,说过nameNode主要是实现一个 blockID 到对应 dataNode的对应关系映射. 现在分析一下腰实现这个映射,nameNode还需要哪些模块. 1 为了方便用户 ...
- tomcat启动出错(转)
刚刚装载好的myeclipse 在添加项目到服务器的时候,突然异常涌现. 其实这是一个新手常见的错误.平常配置JDK环境的时候有些人习惯把JDK安装到磁盘的当前文件夹里,这样十分的方便,但是安装时,你 ...
- BPMN这点事-BPMN扩展元素
什么是BPMN扩展元素?我们为什么要从BPMN元素中界定出一个扩展元素的子集?BPMN扩展元素是我们平时使用频率不高的BPMN元素,这些元素更多的面向开发人员而不是业务人员,它们强调流程执行的细节,例 ...
- dos 实用命令收集
隐藏文件夹: H:\>attrib gho +h +s +r 解决win2012服务器上网慢:netsh int tcp set global ecn=disable
- iOS 开发者必不可少的 75 个工具,你都会了吗
如果你去到一位熟练的木匠的工作室,你总是能发现他/她有一堆工具来完成不同的任务. 软件开发同样如此.你可以从软件开发者如何使用工具中看出他水准如何.有经验的开发者精于使用工具.对你目前所使用的工具不断 ...
- 线上redis服务内存异常分析。
项目中,新增了一个统计功能,用来统计不同手机型号的每天访问pv,看了下redis2.6有个setbit的功能,于是打算尝尝鲜把 redis从2.4更新到了2.6 因为是租了vps.服务器的内存只有4g ...
- Linux makefile教程之条件判断六[转]
使用条件判断 —————— 使用条件判断,可以让make根据运行时的不同情况选择不同的执行分支.条件表达式可以是比较变量的值,或是比较变量和常量的值. 一.示例 下面的例子,判断$(CC)变量是否“g ...