HTML: Options in Struts
Banq http://www.jdon.com Aug 25, 2003 11:19 AM Reply
HTML: Options is a more complex TAGE LIB in Struts, flexible, but STURTS provides the most direct summary of common JSP ACTIONForm in the source code of STURTS, which is now summarized as follows, divided into two cases: array and COLLECTION. Demand, to achieve:
To achieve the above effects, you need two steps:
First: Set Actionform,
Also divided into two small steps: The first small step must be in ActionForm, there is a sentence
PRIVATE COLLECTION Beancollection;
Public Collection getBeancollection ();
Collection Beancollection To ensure an implementation, such as ArrayList, if not, the NO Collection Found is wrong, Struts's greatest inconvenience is once the problem is difficult, do not know where to use errors, or forget what is set.
Because the value of Option and the Label value in front demand are different, then saved in the Beancollection is an object of Value and Label, named LabelValueBean, two attributes in LabelValuebean Value and Label,
Assign a value for Beancollection at a place, such as:
Vector entries = new vector (10); Entries.Add (New Labelvaluebean ("Label 0", "Value 0"); Entries.Add (New LabelValuebean); Entries.Add (New Labelvaluebean ("Label 2", "Value 2")); Entries.Add (New Labelvaluebean ("Label 3", "Value 3")); Entries.Add (New Labelvaluebean ("Label 4", "Value 4 ")); Entries.Add (New Labelvaluebean (" Label 5 "," Value 5 ")); Entries.Add (New Labelvaluebean (" Label 6 "," Value 6 "); Entries.Add (New LabelvalueBean (" Label 7, "Value 7")); Entries.Add (New Labelvaluebean ("Label 8", "Value 8")); Entries.Add (New LabelValuebean ("Label 9", "Value 9"); then Execute setBeancollection (Entries);
This is a value of Beancollection in Actionform.
The second small step, you need to set selected, SELECTED has two, radio and multiple selection:
There must be in ActionForm:
Private string singleselect = "single 5"; public string getsingleselect () {return (this.singLeselect);} public void setsingleselect (string singleselect) {this.singLeselect = Singleselectr;
Or multiple selection, multiple choices must be arrays:
private String [] beanCollectionSelect = { "Value 1", "Value 3", "Value 5"}; public String [] getBeanCollectionSelect () {return (this.beanCollectionSelect);} public void setBeanCollectionSelect (String beanCollectionSelect []) {this .beancollectionselect = beancollectionSelect;
Second: Write the TANG LIB statement in JSP as follows:
The above is HTML: Options Collection solution, if the option value is very small, simply as an array, two steps:
First: In ActionForm,
Private string values [] = {"Magazine", "Journal", "newspaper", "other"}; private string labels [] = {"l-magazine", "l-journal", "l-newspaper" , "L-Other"}; private String selected = "Magazine"; public String getSelected () {return selected;} public void setSelected (String selected) {this.selected = selected;} public String [] getValues () {return PUBLIC VOID SETVALUES (STRING [] Values) {this.values = value;} public string [] getLabels () {return value;} public void setlabels (string [] labels) {this.labels = labels;
The second step in JSP: