第二十二讲:tapestry的Select组件

Select组件,具体效果直接运行实例吧,源码如下:

VariedSelect.java

/**
* 项目名称:TapestryStart
* 开发模式:Maven+Tapestry5.x+Tapestry-hibernate+Mysql
* 网址: http://www.flywind.org
* 版本:1.0
* 编写:飞风
* 时间:2012-02-29
*/
package com.tapestry.app.pages;
 
import org.apache.tapestry5.annotations.Property;
 
public class VariedSelect {
@Property
private String color0;
 
@Property
private String color1;
 
@Property
private String color2;
 
@Property
private String color3;
 
String[] onPassivate() {
return new String[] { color0, color1, color2, color3 };
}
 
void onActivate(String color0, String color1, String color2, String color3) {
this.color0 = color0;
this.color1 = color1;
this.color2 = color2;
this.color3 = color3;
}
}
 

VariedSelect.tml

<html t:type="layout" title="tapestryStart Index"  t:sidebarTitle="Framework Version"
 xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" xmlns:p="tapestry:parameter">
<form t:type="form">
This example demonstrates labelling the blank option.<br/><br/>
 
<t:label for="color0"/>:
<select t:type="select" t:id="color0" t:model="literal:Red,Yellow,Blue" t:blankLabel="Choose..."></select>
<input type="submit" value="Submit"/>
You chose: ${color0}
</form><br/>
 
<form t:type="form">
This example demonstrates labelling the blank option using the page's properties file.<br/><br/>
 
<t:label for="color1"/>:
<select t:type="select" t:id="color1" t:model="literal:Red,Yellow,Blue"></select>
<input type="submit" value="Submit"/>
You chose: ${color1}
</form><br/>
 
<form t:type="form">
This example demonstrates making it mandatory to make a choice.<br/><br/>
 
<t:label for="color2"/>:
<select t:type="select" t:id="color2" t:model="literal:Red,Yellow,Blue" t:validate="required"></select>
<input type="submit" value="Submit"/>
You chose: ${color2}
</form><br/>
 
<form t:type="form">
This example demonstrates making it mandatory to make a choice - but it also has a blank option.<br/><br/>
 
<t:label for="color3"/>:
<select t:type="select" t:id="color3" t:model="literal:Red,Yellow,Blue" t:validate="required" t:blankOption="ALWAYS"></select>
<input type="submit" value="Submit"/>
You chose: ${color3}
</form><br/>
</html>

你可能感兴趣的:(第二十二讲:tapestry的Select组件)