html:checkbox设计步骤

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;
}