JSF select grouping

Source: Internet
Author: User

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.