wicket 综合应用实例-在线匹萨店



 一个wicket 综合应用实例-在线匹萨店

这个例子对初学wicket很有帮助,可以帮助你很好理解wicket开发框架的基本概念,希望能使初学wicket的兄弟快速入门。

 

实现的业务流程如下图:

选择好自己喜欢的匹萨后点击提交,将信息带到下个页面显示出来


Pizza.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>Pizza</title>
	</head>
	<body>
		<form wicket:id="pizzaForm">
			<div style="font-weight: bold;" font-weight="" bold="">
				<big>在线比萨饼店</big>
			</div>
			<table style="text-align: left; width: 600px; height: 200px;"
				border="1" cellpadding="0" cellspacing="0">
				<tbody>
					<tr>
						<td style="font-weight: bold; text-align: right;">
							比萨饼面皮:
						</td>
						<td>
							<select wicket:id="crust">
								<option>
									option 1
								</option>
								<option>
									option 2
								</option>
								<option>
									option 3
								</option>
							</select>
						</td>
					</tr>
					<tr>
						<td style="font-weight: bold; text-align: right;">
							配料:
						</td>
						<td>
							意大利辣香肠
							<input wicket:id="pepperoni" type="checkbox" />
							香肠
							<input wicket:id="sausage" type="checkbox" />
							&nbsp;洋葱
							<input wicket:id="onions" type="checkbox" />
							&nbsp;绿胡椒
							<input wicket:id="greenPeppers" type="checkbox" />
						</td>
					</tr>
					<tr>
						<td style="font-weight: bold; text-align: right;">
							备注:
						</td>
						<td>
							<input maxlength="50" size="50" wicket:id="comments" type="text" />
						</td>
					</tr>
					<tr>
						<td style="text-align: center;" colspan="2">
							<input value="Submit" name="Submit" type="submit" />
						</td>
					</tr>
				</tbody>
			</table>
		</form>
	</body>
</html>

 Pizza.java
 

public class Pizza extends WebPage
{
	public Pizza()
	{
		super();
		PizzaForm pizzaForm = new PizzaForm("pizzaForm");
		add(pizzaForm);
	}

}

 

PizzaForm.java

public class PizzaForm extends Form
{
	private static final long serialVersionUID = 1L;

	private DropDownChoice crustDropDown;

	private CheckBox pepperoniCheckBox = new CheckBox("pepperoni");

	private CheckBox sausageCheckBox = new CheckBox("sausage");

	private CheckBox onionsCheckBox = new CheckBox("onions");

	private CheckBox greenPeppersCheckBox = new CheckBox("greenPeppers");

	private TextField commentsTextField = new TextField("comments");

	public PizzaForm(String id)

	{
		super(id);

		PizzaModel pizzaModel = new PizzaModel();

		setModel(new CompoundPropertyModel(pizzaModel));

		crustDropDown = new DropDownChoice(

		"crust", new PropertyModel(pizzaModel, "crust"), Arrays
				.asList(new CrustType[]

				{ new CrustType("Thin & Crispy"),

				new CrustType("Hand Tossed"),

				new CrustType("Pan Pizza") }),

		new ChoiceRenderer("text", "id"));

		add(crustDropDown);

		add(pepperoniCheckBox);

		add(sausageCheckBox);

		add(onionsCheckBox);

		add(greenPeppersCheckBox);

		add(commentsTextField);

	}

	@Override
	protected void onSubmit()
	{
		PizzaModel pizzaModel = (PizzaModel) getModelObject();
		setResponsePage(new PizzaList(pizzaModel));
	}

}

 

CrustType.java

public class CrustType implements Serializable
{

	private static final long serialVersionUID = 1L;

	private String id;

	private String text;

	public CrustType()
	{
		super();
	}

	public CrustType(String crustName)
	{
		setId(crustName);
		setText(crustName);
	}

	
	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}

	public String getText()
	{
		return text;
	}

	public void setText(String text)
	{
		this.text = text;
	}

	@Override
	public String toString()
	{
		return getText();
	}

}

 

PizzaModel.java

public class PizzaModel implements Serializable
{

	private static final long serialVersionUID = 1L;

	private String crust;

	private boolean pepperoni;

	private boolean sausage;

	private boolean onions;

	private boolean greenPeppers;

	private String comments;

	public String getComments()
	{
		return comments;
	}

	public void setComments(String comments)
	{
		this.comments = comments;
	}

	public String getCrust()
	{
		return crust;
	}

	public void setCrust(String crust)
	{
		this.crust = crust;
	}

	public boolean getGreenPeppers()
	{
		return greenPeppers;
	}

	public void setGreenPeppers(boolean greenPeppers)
	{
		this.greenPeppers = greenPeppers;
	}

	public boolean getOnions()
	{
		return onions;
	}

	public void setOnions(boolean onions)
	{
		this.onions = onions;
	}

	public boolean getPepperoni()
	{
		return pepperoni;
	}

	public void setPepperoni(boolean pepperoni)
	{
		this.pepperoni = pepperoni;
	}

	public boolean getSausage()
	{
		return sausage;
	}

	public void setSausage(boolean sausage)

	{
		this.sausage = sausage;
	}

}

 

PizzaList.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>PizzaList.html</title>

		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="this is my page">
		<meta http-equiv="content-type" content="text/html; charset=gbk">

		<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

	</head>

	<body>
		<table style="text-align: left; width: 600px; height: 200px;"
			border="1" cellpadding="0" cellspacing="0">
			<tbody>
				<tr>
					<td style="font-weight: bold; text-align: right;">
						比萨饼面皮:
					</td>
					<td>
						<span wicket:id="crust">Hello</span>
					</td>
				</tr>
				<tr>
					<td style="font-weight: bold; text-align: right;">
						配料:
					</td>
					<td>
						意大利辣香肠:&nbsp;
						<span wicket:id="pepperoni"></span> 香肠:&nbsp;
						<span wicket:id="sausage"></span>&nbsp;洋葱: &nbsp;
						<span wicket:id="onions"></span>&nbsp;绿胡椒:&nbsp;
						<span wicket:id="greenPeppers"></span>
					</td>
				</tr>
				<tr>
					<td style="font-weight: bold; text-align: right;">
						备注:
					</td>
					<td>
						<span wicket:id="comments"></span>
					</td>
				</tr>
			</tbody>
		</table>


	</body>
</html>

 

PizzaList.java

public class PizzaList extends WebPage
{

	/**
	 * 
	 */
	public PizzaList()
	{
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param model
	 */
	public PizzaList(IModel<?> model)
	{
		super(model);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param pageMap
	 */
	public PizzaList(IPageMap pageMap)
	{
		super(pageMap);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param parameters
	 */
	public PizzaList(PageParameters parameters)
	{
		super(parameters);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param pageMap
	 * @param model
	 */
	public PizzaList(IPageMap pageMap, IModel<?> model)
	{
		super(pageMap, model);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param pageMap
	 * @param parameters
	 */
	public PizzaList(IPageMap pageMap, PageParameters parameters)
	{
		super(pageMap, parameters);
		// TODO Auto-generated constructor stub
	}

	public PizzaList(PizzaModel pizzaModel)

	{

		super();

		add(new Label("crust", pizzaModel.getCrust()));

		add(new Label("pepperoni", new Boolean(pizzaModel.getPepperoni())

		.toString()));

		add(new Label("sausage", new Boolean(pizzaModel.getSausage())
				.toString()));

		add(new Label("onions", new Boolean(pizzaModel.getOnions()).toString()));

		add(new Label("greenPeppers", new Boolean(pizzaModel.getGreenPeppers())

		.toString()));

		add(new Label("comments", pizzaModel.getComments()));

	}

}

 

页面的跳转、Model的运用、页面元素的构造都运用到了,是个很不错的wicket教程,希望大家喜欢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值