2 Replies Latest reply on Aug 11, 2008 10:28 AM by ptfp

    Changing values of HtmlSelect components

    ptfp

      Hello,
      I need to change the value of a dropdown menu (t:selectOneMenu) in my application.
      I have built JSFUnit from the latest svn version and I am using the classes from the jsfunit package instead of the facade classes.
      When I try to use the setValue method of JSFClientSession I get the following exception:

      java.lang.IllegalArgumentException: This method can not be used on components of type com.gargoylesoftware.htmlunit.html.HtmlSelect
      at org.jboss.jsfunit.jsfsession.JSFClientSession.setValue(JSFClientSession.java:156)
      ...


      Is there another way to do this?

        • 1. Re: Changing values of HtmlSelect components

          One way is to click() the selectitem if they are declared:

           <h:selectOneMenu 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"/>
           </h:selectManyListbox>
          

           JSFSession jsfSession = new JSFSession("/indexWithExtraComponents.faces");
           JSFClientSession client = jsfSession.getJSFClientSession();
           JSFServerSession server = jsfSession.getJSFServerSession();
          
           client.click("selectMonday");
           client.click("selectWednesday");
           client.click("selectFriday");
           client.click("submit_button");
          


          Another way if you don't have declared selectItems is to find the selectitem from the select control and click it directly:

           HtmlSelect htmlSelect = (HtmlSelect)client.getElement(controlId);
           HtmlOption htmlOption = htmlSelect.getOptionByValue(value);
           htmlOption.click();
          



          • 2. Re: Changing values of HtmlSelect components
            ptfp

            Yes, that works. Thanks a lot!