第二十二講:tapestry的Select組件

Select組件,具體效果直接運行實例吧,源碼以下:html

VariedSelect.javajava

/**
* 項目名稱:TapestryStart
* 開發模式:Maven+Tapestry5.x+Tapestry-hibernate+Mysql
* 版本: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.tmlsql

<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>
相關文章
相關標籤/搜索