5 Replies Latest reply on Jun 18, 2008 10:57 PM by Tim Evers

    Is JSFClientSession.setChecked broken?

    Tim Evers Master

      The code in question is this:

      public void setChecked(String componentID, boolean isChecked) throws IOException
       {
       Element element = getElement(componentID);
       if (element instanceof HtmlCheckBoxInput) ((HtmlCheckBoxInput)element).setChecked(isChecked);
       throw new IllegalArgumentException("This method can not be used on components of type " + element.getClass().getName());
       }
      


      It seems to me that no matter if the element is a HtmlCheckBoxInput or not the IllegalArgumentException is thrown. I'm pretty sure there is an 'else' missing here? Or am I losing my mind!? LOL

        • 1. Re: Is JSFClientSession.setChecked broken?
          Stan Silvert Master

          No you haven't lost your mind, but I have. This method was never tested. Our unit test for checkbox doesn't call this method. It just uses plain old click():

          public void testSetCheckbox() throws IOException
           {
           client.click("funcheck"); // uncheck it
           client.click("submit_button");
           assertFalse((Boolean)server.getManagedBeanValue("#{checkbox.funCheck}"));
          
           client.click("funcheck"); // make it checked again
           client.click("submit_button");
           assertTrue((Boolean)server.getManagedBeanValue("#{checkbox.funCheck}"));
           }


          I think the setChecked() method should just be removed from JSFClientSession. What do you think?

          Stan



          • 2. Re: Is JSFClientSession.setChecked broken?
            Tim Evers Master

            Well, that depends on how hard it is to get the current status of the checkbox.

            If I want to do a test where the checkbox is set to true... I don't want to rely on my own knowledge that it was false before.
            I just want to know that I am setting it to true.

            This would seem easier to do by the setChecked method in my opinion. But I can see how that the click method is more 'life like'.

            I havn't really taken the time to check how to get the value of the checkbox so....I'm not sure how much work is involved in that yet.

            • 3. Re: Is JSFClientSession.setChecked broken?
              Stan Silvert Master

               

              "Kragoth" wrote:

              I havn't really taken the time to check how to get the value of the checkbox so....I'm not sure how much work is involved in that yet.


              From the client side, you just do this:
              HtmlCheckBoxInput checkbox = (HtmlCheckBoxInput)jsfClientSession.getElement(componentID);
              boolean isChecked = checkbox.isChecked();


              Or you can get it from the server side using JSFServerSession.getManagedBeanValue() or JSFServerSession.getComponentValue().

              Stan

              • 4. Re: Is JSFClientSession.setChecked broken?
                Stan Silvert Master

                 

                "Kragoth" wrote:

                If I want to do a test where the checkbox is set to true... I don't want to rely on my own knowledge that it was false before.
                I just want to know that I am setting it to true.

                This would seem easier to do by the setChecked method in my opinion. But I can see how that the click method is more 'life like'.

                We've got some thinking to do. This kind of thing came up in another thread earlier today. You can always drop back to the HtmlUnit API for this stuff after you call client.getElement(componentID).

                One man's great feature is another man's API bloat. It's tough to decide on a good balance.

                Stan

                • 5. Re: Is JSFClientSession.setChecked broken?
                  Tim Evers Master

                  I agree, I'm just trying to make it easier for me :P
                  I can always add the method I want to my api and that way the get Element etc code is abstracted away from the other developers. I'm trying to make using JSFUnit testing as easy as possible for them.

                  But where the line should be drawn on this is very hard. Probly wouldn't hurt that much to remove it. As it seems that it's not that hard to check the value manually.