Using "select" components (Listbox, Radio, Menu, etc)

Version 1

    "Select" components such as <h:selectOneMenu> or <h:selectManyListbox> allow you to select one or more items in a component.  The JSF components <f:selectItem> and <f:selectItems> allow you to specify which items can be chosen.


    How you select the items in a JSFUnit test depends on whether you use <f:selectItem> or <f:selectItems>.  For <f:selectItem> the values are explicitly set in your JSF page and it's easy to click on a particular item in your test:

    <h:selectManyListbox id="Weekdays">
       <f:selectItem id="selectMonday" itemValue="Monday"/>
       <f:selectItem id="selectTuesday" itemValue="Tuesday"/>
       <f:selectItem id="selectWednesday" itemValue="Wednesday"/>
       <f:selectItem id="selectThursday" itemValue="Thursday"/>
       <f:selectItem id="selectFriday" itemValue="Friday"/>
       <f:selectItem id="selectSaturday" itemValue="Saturday"/>


    To click one of these items in my test I would do the following:

    JSFClientSession client = jsfSession.getJSFClientSession();"selectMonday");


    If you are using <f:selectItems> you don't easily know the id that needs to be "clicked".  So you would Using the HtmlUnit API with JSFUnit :

    <h:selectManyListbox id="WeekdaysUsingSelectItems">
       <f:selectItems id="WeekdayItems" value="#{weekdaylist}"/>
     JSFClientSession client = jsfSession.getJSFClientSession();   
     HtmlSelect select = (HtmlSelect)client.getElement("WeekdaysUsingSelectItems");