In web development, there are frequent grouping requirements for the drop-down select box (select). For example, the Sega model selection shown in, take the sedan 1.6l as an example.
In the figure, "Sega 2011 sedan 1.6 automatic" and "Sega 2011 sedan 1.6 manual" are selected as select groups. The following describes how to implement them in JSF.
Method 1: Use selectitemgroup
XHTML code:
<H: Form> <Fieldset> <Legend> JSF select group processing </legend> <H: outputtext value ="Sega 1.6l Model Selection :"/> <H: selectonemenu value ="# {Testmb. cartype }"> <F: selectitems value ="# {Testmb. cartypes }"> </F: selectitems> </H: selectonemenu> </Fieldset> </H: Form> |
Java code:
PrivateString cartype; PublicString getcartype (){ ReturnCartype; } Public voidSetcartype (string value ){ This. Cartype = value; } PublicList <selectitem> getcartypes (){ List <selectitem> items =NewArraylist <selectitem> (); Selectitemgroup group1 =NewSelectitemgroup ("Sega 2011 sedan 1.6 automatic "); Group1.setselectitems (NewSelectitem [] { NewSelectitem ("auto fashion", "auto fashion "), NewSelectitem ("automatic champion", "automatic champion "), NewSelectitem ("automatic exclusive", "automatic exclusive "), NewSelectitem ("automatic luxury", "automatic luxury ") }); Items. Add (group1 ); Selectitemgroup group2 =NewSelectitemgroup ("Sega 2011 sedan 1.6 manual "); Group2.setselectitems (NewSelectitem [] { NewSelectitem ("manual fashion", "manual fashion "), NewSelectitem ("manual champion", "manual champion "), NewSelectitem ("manual comfort", "manual comfort ") }); Items. Add (group2 ); ReturnItems; } |
Method 2: Use selectitem disable
XHTML code: Same as above
Java code:
PrivateString cartype; PublicString getcartype (){ ReturnCartype; } Public voidSetcartype (string value ){ This. Cartype = value; } PublicList <selectitem> getcartypes (){ List <selectitem> items =NewArraylist <selectitem> (); Items. Add (NewSelectitem ("Sega 2011 sedan 1.6 automatic", "Sega 2011 sedan 1.6 automatic ","",True)); Items. Add (NewSelectitem ("auto fashion", "auto fashion ")); Items. Add (NewSelectitem ("automatic champion", "automatic champion ")); Items. Add (NewSelectitem ("automatic exclusive", "automatic exclusive ")); Items. Add (NewSelectitem ("automatic luxury", "automatic luxury ")); Items. Add (NewSelectitem ("Sega 2011 sedan 1.6 manual", "Sega 2011 sedan 1.6 manual ","",True)); Items. Add (NewSelectitem ("manual fashion", "manual fashion ")); Items. Add (NewSelectitem ("manual champion", "manual champion ")); Items. Add (NewSelectitem ("manual comfort", "manual comfort ")); ReturnItems; } |
Because IE6 and IE7 do not support the option disable attribute, setting the selectitem disable fails under IE6 and IE7. We recommend that you use selectitemgroup. The corresponding HTML element is optgroup.
Share button