7 Replies Latest reply on Oct 12, 2010 7:56 PM by ssilvert

    JSFUnit fails to set back value for backing bean List property

    fastregister

      My JSF xhtml page has a radio button <h:selectOneRadio> which connects directly to a first item of the backing bean List property:

       

      <h:selectOneRadio id="coverRequired_0" options="#{jsfHelper.yesNoOptions}" value="#{backingBean.myList[0]}">
           <a4j:support event="onclick" ajaxSingle="true" reRender="myTable" action="#{backingBean.doIT}">
      </h:selectOneRadio>


      This works fine in browsers but not with JSFUnit.

       

      I try to set the radio to "Yes", and read back the value. The client side value of the radio is correct, but the server side value of the backing bean property is not set at all.

      It seems that JSFUnit doesn't support EL with List notation e.g. #{backingBean.myList[0]}.

       

      I am stuck with this one and need your help please.

        • 1. Re: JSFUnit fails to set back value for backing bean List property
          ssilvert

          Can you post your JSFUnit code for this?

           

          You say that this works in the browser.  How can you tell from the browser that the backing bean was changed?

           

          Stan

          • 2. Re: JSFUnit fails to set back value for backing bean List property
            fastregister

            hi Stan,

            here is a segment of my JSFUnit code:

             

                    //radio group with Yes/No options
                    HtmlRadioButtonInput radioYes = (HtmlRadioButtonInput)client.getElement("coverRequired_0:0");
                    HtmlRadioButtonInput radioNo = (HtmlRadioButtonInput)client.getElement("coverRequired_0:1");
                    assertNotNull("Radio Yes button is not present.", radioYes); // ==> PASSED
                    assertNotNull("Radio No button is not present.", radioNo); // ==> PASSED
                    
                    //assert initial values
                    assertEquals(false, radioYes.isChecked()); // ==> PASSED
                    assertEquals(false, radioNo.isChecked());  // ==> PASSED
                    
                    //click Yes
                    client.click("coverRequired_0:0");
                    radioYes = (HtmlRadioButtonInput)client.getElement("coverRequired_0:0");     
                    radioNo = (HtmlRadioButtonInput)client.getElement("coverRequired_0:1");
                    assertEquals(true, radioYes.isChecked()); // ==> PASSED
                    assertEquals(false, radioNo.isChecked()); // ==> PASSED       
                    
                    //assert backing bean value: should have been set to TRUE
                    List<Boolean> list = (List<Boolean>)server.getManagedBeanValue("#{backingBean.myList}");
                    assertEquals(Boolean.TRUE, list.get(0)); // ==> FAILED: the value is NULL
            
                    //click No
                    client.click("coverRequired_0:1");
                    radioYes = (HtmlRadioButtonInput)client.getElement("coverRequired_0:0");     
                    radioNo = (HtmlRadioButtonInput)client.getElement("coverRequired_0:1");
                    assertEquals(false, radioYes.isChecked()); // ==> PASSED
                    assertEquals(true, radioNo.isChecked());   // ==> PASSED    
                    
                    //assert backing bean value: should have been set to FALSE
                    List<Boolean> list2 = (List<Boolean>)server.getManagedBeanValue("#{backingBean.myList}");
                    assertEquals(Boolean.FALSE, list.get(0)); // ==> FAILED: the value is NULL
            

             

            Without JSFUnit, the code works fine in browsers (the backing bean values were set, we can verify this when we load a saved document, or by looking at the DB values).

            • 3. Re: JSFUnit fails to set back value for backing bean List property
              ssilvert

              Other examples I see using <a4j:support> with <h:selectOneRadio> will use onchange instead of onclick.  You could give that a try.

               

              I suspect what is happening is that what you are clicking with HtmlUnit/JSFUnit is not firing the event.  One approach is to use Firebug to find out the true recipient of the onclick event when someone clicks in the browser.  Then change your code to click on the element that is really getting clicked.

               

              Also, you can use the htmlunit snooper to see what ajax requests are (or are not) going to the server.

               

              BTW, I'm sure it's not a problem with JSFUnit and EL's list notation.  JSFUnit just passes the string into the native EL engine.

               

              Stan

              • 4. Re: JSFUnit fails to set back value for backing bean List property
                fastregister

                Actually it's not the List problem, I sent the last 3 days debuging, and it turns out to be the problem of A4J requests.

                According to my tests, JSFUnit only fires a single A4J request and ignoring the subsequence ones (i.e. if I have a sequence of requests, only the first one get fired).

                Below are my tests:

                        client.setValue("val1", "2009");
                        assertEquals("2009", server.getManagedBeanValue("#{myBean.val1}"));
                       
                        client.setValue("val2", "2010");
                        assertEquals("2010", server.getManagedBeanValue("#{myBean.val2}"));

                 

                and the xhtml part:

                        <h:inputText id="val1" value="#{myBean.val1}">   
                            <a4j:support event="onchange" ajaxSingle="true"/>                                       
                        </h:inputText>
                       
                        <h:inputText id="val2" value="#{myBean.val2}">   
                            <a4j:support event="onchange" ajaxSingle="true"/>                                       
                        </h:inputText>

                 

                Only the first test passes, the second returns NULL value (i.e. not set).

                I change the order of the test, there's still only one a4j request get fired for whatever the first test on the queue.

                 

                Any idea why it behaves like that?

                 

                Thanks

                • 5. Re: JSFUnit fails to set back value for backing bean List property
                  ssilvert

                  This works fine for me.  I added a test to one of the JSFUnit tests to demonstrate.

                   

                  See http://anonsvn.jboss.org/repos/jsfunit/trunk/jboss-jsfunit-examples/jboss-jsfunit-examples-ajax4jsf/

                   

                  The new test is A4jSupportTest.java.  It runs against a4jsupport.xhtml.

                   

                  If you want to build and run the example yourself see the Building JSFUnit page.

                   

                  Stan

                  • 6. Re: JSFUnit fails to set back value for backing bean List property
                    fastregister

                    I tried your example in my envirolment, still only the first Ajax request is fired.

                    Something's very wrong but I don't know where.

                     

                    Any suggestion?

                     

                    Thanks

                    • 7. Re: JSFUnit fails to set back value for backing bean List property
                      ssilvert

                      I'd start with checking the versions of all your jars.

                       

                      Have you tried to build and run my example or did you just move the code into your project?  If you can get my example to work on its own then it's just a matter of figuring out what is different in your build.

                       

                      Stan