1 2 Previous Next 19 Replies Latest reply on Jun 27, 2008 12:36 AM by kragoth

    New JSFUnit and rich:panelMenuItem

    kragoth

      Has anyone been able to get the new JSFUnit working with rich:panelMenu and the rich:panelMenuItem?

      Currently I'm just trying the client.click("id of my panelMenuItem") and nothing seems to be happening.

      The .xhtml snippet

      ....
      <rich:panelMenu id="sideMenu" styleClass="SideMenuPanel"
       expandSingle="true"
       disabled="#{GekkoWebContext.isPrimaryNavigationDisabled()}"
       disabledGroupClass="disabledMenu"
       disabledItemClass="disabledMenuItem">
      
       <rich:panelMenuGroup id="searchGroup" label="Search"
       iconCollapsed="/images/search_icon.gif"
       iconExpanded="/images/search_icon.gif"
       binding="#{SideMenuBinding.searchMenu}">
      
       <rich:panelMenuItem id="gotoTenureSearch" label="Tenure"
       action="#{MainMenuController.searchTenure}" />
      


      java code snippet
      ...
      public void clickTenureSearch() throws IOException, SAXException {
       client.click("gotoTenureSearch");
       }
      



      When the click happens I get this line in my logs
      09:37:10.118 DEBUG [http-8080-2] com.gargoylesoftware.htmlunit.html.HtmlDivision - Firing Event click (Current Target: HTMLElement for HtmlDivision[<div id="MasterPageForm:gotoTenureSearch">]);
      


      But nothing happens. The action that should happen when clicking on this panelMenuItem does not occur.

        • 1. Re: New JSFUnit and rich:panelMenuItem
          ssilvert

          Look at the HTML source for the page and see how it is rendered. I'm guessing that there is no onclick action for the tag. What I'm finding is that sometimes JSFUnit will need a little more intelligence to figure out what it really needs to click. I'm working on that now.

          Stan

          • 2. Re: New JSFUnit and rich:panelMenuItem
            ssilvert

            I just comitted some changes that could fix this. It depends on how the component got rendered.

            Stan

            • 3. Re: New JSFUnit and rich:panelMenuItem
              kragoth

              The changes did not fix the problem. I'm getting exactly the same problem.

              Sorry :(

              • 4. Re: New JSFUnit and rich:panelMenuItem
                ssilvert

                OK. Back to my original question. What actually gets rendered in the HTML? The div tag probably doesn't have an onclick. It's probably some other tag inside the div that JSFUnit needs to find.

                Stan

                • 5. Re: New JSFUnit and rich:panelMenuItem
                  kragoth

                  I've emailed you the html output. It's causing problems posting it on the forum.

                  If you don't get the email please let me know.

                  Thanks again for your help.

                  • 6. Re: New JSFUnit and rich:panelMenuItem
                    ssilvert

                    The html we are interested in is this:

                    <div id="MasterPageForm:gotoTenureSearch">
                     <table border="0" cellpadding="0" cellspacing="0" class="dr-pmenu-item rich-pmenu-item " id="tablehideMasterPageForm:gotoTenureSearch">
                     <tbody>
                     <tr id="row_MasterPageForm:gotoTenureSearch">
                     <td class="dr-pmenu-nowrap rich-pmenu-item-icon ">
                     <img src="/gekko-tje/a4j_3_2_0-SNAPSHOTorg.richfaces.renderkit.html.iconimages.PanelMenuIconSpacer/DATB/eAH7..8.AAX9Av4_" alt="" hspace="0" vspace="0" height="16" width="16" />
                     <img src="/gekko-tje/a4j_3_2_0-SNAPSHOTorg.richfaces.renderkit.html.iconimages.PanelMenuIconGrid/DATB/eAH7..8.AAX9Av4_" alt="" vspace="0" hspace="0" width="16" height="16" id="leftIconMasterPageForm:gotoTenureSearch" />
                     </td>
                     <td class="dr-pmenu-group-self-label rich-pmenu-item-label" id="iconMasterPageForm:gotoTenureSearch" style="width:100%">
                     <input name="panelMenuActionMasterPageForm:gotoTenureSearch" type="hidden" />Tenure
                     </td>
                     <td>
                     <img src="/gekko-tje/a4j_3_2_0-SNAPSHOTorg.richfaces.renderkit.html.iconimages.PanelMenuIconSpacer/DATB/eAH7..8.AAX9Av4_" alt="" vspace="0" hspace="0" width="16" height="16" id="rightIconMasterPageForm:gotoTenureSearch" />
                     </td>
                     </tr>
                     </tbody>
                     </table>
                    </div>

                    One of the tags above is the one that needs to be "clicked". At this point, I don't know which one it is. I'd need to do a lot of digging. RichFaces isn't using the plain ID for the target item. It used the plain id for the div tag which we know is not the one you want. So you need to experiment to see which one will make it work. If you have a tool in your browser that logs javascript events then you can find it that way. Otherwise, you will try HtmlUnit code on the different tags until you find the right one.

                    So you can do something like:
                    HtmlPage htmlPage = (HtmlPage)client.getContentPage();
                    ClickableElement clickable = (ClickableElement)htmlPage.getElementById("iconMasterPageForm:gotoTenureSearch");
                    clickable.click();


                    At one point I thought that with HtmlUnit we would no longer need the RichFacesClient, but obviously it will still be needed. At least the code for it will be relatively simple. We'll just need code like that above for each component that generates odd ID's.

                    Stan

                    • 7. Re: New JSFUnit and rich:panelMenuItem
                      kragoth

                      Thanks Stan!!!
                      Your suggestion worked perfectly! Oviously I would definitly like this to be hidden behind the richfaces client or a helper method of some sort. But this has got me going!

                      I have a problem with setChecked now but I'll put that in another thread.

                      Thanks again!

                      • 8. Re: New JSFUnit and rich:panelMenuItem
                        ssilvert

                         

                        "Kragoth" wrote:
                        Thanks Stan!!!
                        Your suggestion worked perfectly! Oviously I would definitly like this to be hidden behind the richfaces client or a helper method of some sort.

                        I'll definitely put this in a new version of RichFacesClient.

                        BTW, which component had to be clicked? You can save me some time when I go to implement it later.

                        Stan

                        • 9. Re: New JSFUnit and rich:panelMenuItem

                          Kargoth: I have a couple of questions:

                          1) What version of richfaces are you using?
                          2) Which component id did you use to make this work?

                          I'm using 3.2.1 GA and I've tried each component contained in a RichMenuItem:

                          <div id="mainDisplay:menu:menuForm:logoutMenuItem">
                           <table border="0" cellpadding="0" cellspacing="0" class="dr-pmenu-item rich-pmenu-item " id="tablehidemainDisplay:menu:menuForm:logoutMenuItem">
                           <tbody>
                           <tr id="row_mainDisplay:menu:menuForm:logoutMenuItem">
                           <td class="dr-pmenu-nowrap rich-pmenu-item-icon ">
                           <img src="/project/a4j_3_2_1-SNAPSHOTorg.richfaces.renderkit.html.iconimages.PanelMenuIconSpacer/DATB/eAHbWuoFAANWAXU_.faces" alt="" hspace="0" vspace="0" height="16" width="16" />
                           </td>
                           <td class="dr-pmenu-group-self-label rich-pmenu-item-label" id="iconmainDisplay:menu:menuForm:logoutMenuItem" style="width:100%">
                           <input name="panelMenuActionmainDisplay:menu:menuForm:logoutMenuItem" type="hidden" />Log Off
                           </td>
                           <td>
                           <img src="/project/a4j_3_2_1-SNAPSHOTorg.richfaces.renderkit.html.iconimages.PanelMenuIconSpacer/DATB/eAHbWuoFAANWAXU_.faces" alt="" vspace="0" hspace="0" width="16" height="16" id="rightIconmainDisplay:menu:menuForm:logoutMenuItem" />
                           </td>
                           </tr>
                           </tbody>
                           </table>
                          </div>
                          


                          Its pretty clear this doesn't match the dump previously posted.
                          I've traced through the richfaces code and found that the "onclick" handler is bound to the "tablehidemainDisplay:..." component, but the following code certainly doesn't work.

                          HtmlPage htmlPage = (HtmlPage)client.getContentPage();
                          ClickableElement clickable = (ClickableElement)htmlPage.getElementById("tablehidemainDisplay:menu:menuForm:"+controlId);
                          clickable.click();
                          


                          Stan: Perhaps this is a htmlunit issue?

                          • 10. Re: New JSFUnit and rich:panelMenuItem
                            ssilvert

                             

                            "bgregory" wrote:
                            Stan: Perhaps this is a htmlunit issue?

                            Perhaps. It looks like the HTML matches though. What is different? (Note: I reformatted Kargoth's HTML before I posted it)

                            Stan

                            • 11. Re: New JSFUnit and rich:panelMenuItem

                              Sorry, yes, the html matches. I was thinking the IDs didn't match but that is probably due to the fact that my clip is nested inside a group.

                              I'm currently trying to reproduce this with just HtmlUnit.

                              • 12. Re: New JSFUnit and rich:panelMenuItem
                                ssilvert

                                Hmm. So I guess that makes you wonder why Kragoth's is working but yours is not?

                                I'll ping him privately and see if he has time to answer.

                                Stan

                                • 13. Re: New JSFUnit and rich:panelMenuItem

                                  It seems to me that not all of the javascript is running (thus HtmlUnit, or js/parser problem?) I've had to write some helpers for our tests that set the hidden values for some richfaces controls (inplace input, picklist, etc) because using focus() or click() on the htmlUnit component doesn't run the javascript. Also, I've seen some cases (not covered by the richfaces demo) that produce javascript errors (try setting selectOnEdit="true" for an inplace input and then focus() or click() the control)

                                  I saw that you were trying to convince the HtmlUnit guys (Ahmed Ashour ?) to add the richfaces demo to their test suite (great idea!) but I'm thinking there are cases not covered by the demo.

                                  Brian

                                  • 14. Re: New JSFUnit and rich:panelMenuItem

                                    Ok, running with DEBUG logging (and simple example) it appears to be doing SOMETHING when I click() the panelMenuItem table:

                                    15:17:10,084 DEBUG [HtmlTableRow] Firing Event propertychange (Current Target: HTMLElement for HtmlTableRow[<tr id="row_mainDisplay:j_id6" class="">]);
                                    15:17:10,084 DEBUG [HtmlTableRow] Firing Event propertychange (Current Target: HTMLElement for HtmlTableRow[<tr id="row_mainDisplay:j_id6" class="">]);
                                    15:17:10,085 DEBUG [HtmlTableRow] Firing Event propertychange (Current Target: HTMLElement for HtmlTableRow[<tr id="row_mainDisplay:logoutMenuItem" class="">]);
                                    15:17:10,085 DEBUG [HtmlTableRow] Firing Event propertychange (Current Target: HTMLElement for HtmlTableRow[<tr id="row_mainDisplay:logoutMenuItem" class="">]);
                                    15:17:10,086 DEBUG [HtmlTableRow] Firing Event propertychange (Current Target: HTMLElement for HtmlTableRow[<tr id="row_mainDisplay:logoutMenuItem" class="dr-pmenu-selected-item">]);
                                    15:17:10,087 DEBUG [HtmlTableRow] Firing Event propertychange (Current Target: HTMLElement for HtmlTableRow[<tr id="row_mainDisplay:logoutMenuItem" class="dr-pmenu-selected-item rich-pmenu-selected-element">]);
                                    15:17:10,087 DEBUG [HtmlHiddenInput] Firing Event propertychange (Current Target: HTMLElement for HtmlHiddenInput[<input id="mainDisplay:j_id5selectedItemName" name="mainDisplay:j_id5selectedItemName" type="hidden" value="logoutMenuItem">]);
                                    15:17:10,087 DEBUG [HtmlHiddenInput] Firing Event propertychange (Current Target: HTMLElement for HtmlHiddenInput[<input name="panelMenuActionmainDisplay:logoutMenuItem" type="hidden" value="mainDisplay:logoutMenuItem">]);
                                    15:17:10,097 DEBUG [HtmlForm] Firing Event propertychange (Current Target: HTMLElement for HtmlForm[<form id="mainDisplay:j_id5:_form" name="mainDisplay:j_id5:_form" method="post" style="margin:0; padding:0; display: inline;" action="/project/index.faces;jsessionid=DEAA4A815A3F4CA14DF144BBE554B7F9" target="">]);
                                    15:17:10,097 DEBUG [HtmlForm] Firing Event propertychange (Current Target: HTMLElement for HtmlForm[<form id="mainDisplay:j_id5:_form" name="mainDisplay:j_id5:_form" method="post" style="margin:0; padding:0; display: inline;" action="/project/index.faces;jsessionid=DEAA4A815A3F4CA14DF144BBE554B7F9" target="">]);
                                    15:17:10,098 DEBUG [HtmlHiddenInput] Firing Event propertychange (Current Target: HTMLElement for HtmlHiddenInput[<input name="panelMenuActionmainDisplay:logoutMenuItem" type="hidden" value="">]);
                                    


                                    Although the table doesn't seem to be in there, and it clearly doesn't navigate as expected. (The Page that comes back from the click() is the same)

                                    Brian

                                    1 2 Previous Next