1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | package com.strutsrecipes; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; public final class CheckboxTestForm extends ActionForm { // Instance Variables /*Mountains "pre-selected"...*/ private String[] selectedMountains = {"Everest","K2","Lhotse"}; /*the ten tallest Mountains to iterate through*/ private String[] mountains = {"Everest","K2","Kangchenjunga","Lhotse", "Makalu","Kangchenjunga South", "Lhotse Middle","Kangchenjunga West", "Lhotse Shar","Cho Oyu"}; /*Getter for selectedMountains*/ public String[] getSelectedMountains() { return this.selectedMountains; } /*Setter for selectedMountains*/ public void setSelectedMountains(String[] selectedMountains) { this.selectedMountains = selectedMountains; } /*Getter for the mountains*/ public String[] getMountains() { return this.mountains; } /*Setter for the mountains*/ public void setMountains(String[] mountains) { this.mountains = mountains; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%> <%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> <%@taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%> <%-- html code, etc... --> <html:form action="/FormAction" name="testForm" type="com.strutsrecipes.CheckboxTestForm"> <h4><bean:message key="testForm.instruction"/></h4> <logic:iterate name="testForm" property="mountains" id="mountain"> <%-- create the checkbox and selected attribute --> <html:multibox property="selectedMountains"> <bean:write name="mountain"/> </html:multibox> <%-- create the label, note that "br" tag will format it vertically --> <bean:write name="mountain"/><br/> </logic:iterate> <br/> <html:submit/><html:reset/> </html:form> <%-- some more html code, etc... --> |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |