html:checkbox設計方法

複選框的設計:複選框在struts的設計非常靈活,也是使用非常多的一種form的類型。
第一種使用Map操作。頁面設計,()的爲key值:

<html:checkbox property="linuxdist(redhat)" value="Redhat/Fedora Linux"/>Redhat/Fedora Linux<br>
<html:checkbox property="linuxdist(mdk)" value="Mandrake Linux"/>Mandrake Linux<br>
<html:checkbox property="linuxdist(suse)" value="Suse Linux"/>Suse Linux<br>
<html:checkbox property="linuxdist(debian)" value="Debian/Debian-based Linux"/>Debian/Debian-based Linux<br>
<html:checkbox property="linuxdist(none)" value="None above"/>None above


SurveyForm
中的對應代碼。

private Map linuxdists=new HashMap();

public void setLinuxdists(Map linuxDists){
this.linuxdists=linuxDists;
}

public Map getLinuxdists(){
return linuxdists;
}

public void setLinuxdist(String key,String value){
linuxdists.put(key, value);
}

public String getLinuxdist(String key){
return (String)linuxdists.get(key);
}

注意其中的單數和複數。
第二種,數組的使用,property使用同一值。對應的頁面中和ActionForm的定義。

<html:checkbox property="perferredDesktop" value="Gnome"/>Gnome<br>
<html:checkbox property="perferredDesktop" value="KDE"/>KDE<br>
<html:checkbox property="perferredDesktop" value="XFCE"/>XFCE<br>
<html:checkbox property="perferredDesktop" value="Other window manager" />Other window manager

 

private String[] perferredDesktop;
public void setPerferredDesktop(String[] perferredDesktop){
this.perferredDesktop=perferredDesktop;
}

public String[] getPerferredDesktop(){
return perferredDesktop;
}


第三種,boolean型的使用,當需要選擇是和否,使用這種情況,此屬性返回truefalse

<html:checkbox property="surveyPublic" />

SurveyForm 中的定義:

private boolean surveyPublic ;
public void setSurveyPublic(boolean surveyPublic){
this.surveyPublic=surveyPublic;
}

public boolean isSurveyPublic(){
return surveyPublic;
}

發佈了30 篇原創文章 · 獲贊 0 · 訪問量 1283
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章