11 Replies Latest reply: Jul 21, 2010 2:04 PM by Stan Silvert RSS

test rich:tree click

Dont Mind Newbie

hello,

i've two trees in my page.
one is for profiles and the other one for views.
if i select a profile than the view tree is rerendered.

<body>
 <richfaces:panel id="searchTreePanelId" styleClass="leftBox">
 <a4j:outputPanel id="profileTreeOutputPanelId">
 <h:form id="profileTreeFormId">
 <richfaces:tree id="profileTreeId"
 nodeSelectListener="#{Search.profileTreeSelection}"
 ajaxSubmitSelection="true"
 switchType="client"
 reRender="viewTreeOutputPanelId"
 value="#{Search.profileTreeNode}" var="item">
 </richfaces:tree>
 </h:form>
 </a4j:outputPanel>
 <a4j:outputPanel id="viewTreeOutputPanelId">
 <h:form id="viewTreeFormId">
 <richfaces:tree id="viewTreeId"
 nodeSelectListener="#{Search.viewTreeSelection}"
 ajaxSubmitSelection="true"
 switchType="client"
 reRender="searchMask"
 value="#{Search.viewTreeNode}" var="item">
 </richfaces:tree>
 </h:form>
 </a4j:outputPanel>
 </richfaces:panel>
 </body>


the profile tree rerenders the view tree iff a leaf is selected.

public void profileTreeSelection(NodeSelectedEvent event) {
 HtmlTree tree = (HtmlTree) event.getComponent();
 TreeNodeImpl currentNode = (TreeNodeImpl) tree.getModelTreeNode(tree.getRowKey());
 if (currentNode.isLeaf()){
 // call Web Service
 List<View> views = ...
 // create view tree
 rootViewNode = new TreeNodeImpl();
 TreeNode newViewNode = new TreeNodeImpl();
 newViewNode.setData(mf.getMessage("search.tree.rootView.view"));
 newViewNode.addChild(new Integer(1), new TreeNodeImpl());
 rootViewNode.addChild(new Integer(1), newViewNode);

 int counter = 1;
 // Hinzufügen der Views von Web Service
 for(View viewInfo : views){
 TreeNodeImpl newChildNode = new TreeNodeImpl();
 newChildNode.setData(viewInfo);
 newViewNode.addChild(new Integer(counter++), newChildNode);
 }
 }
 }


my problem is now, how can i simulate a click on a leaf via jsfunit?
i already tried a lot of things:

* richFacesClient.clickTreeNodeHandle(...) -> no component Id found
* client.getElement(...).click() -> nothing happended
* client.getElement(...).fireEvent(Event.TYPE_SUBMIT/FOCUS/CHANGE) -> nothing happended
* ...

for now i'm quite uninspired ... ,-|

may you have any ideas?

thanks
hiro


  • 1. Re: test rich:tree click
    Stan Silvert Master

    When all else fails, fall back to the HtmlUnit API:
    http://www.jboss.org/community/wiki/UsingtheHtmlUnitAPIwithJSFUnit

    It's also helpful to run your application with the Firefox FireBug plugin. That lets you see the component ID and make sure your code is calling click() on the right HTML component.

    Stan

  • 2. Re: test rich:tree click
    Dont Mind Newbie

    hello stan,

    thanks for your reply ,-)

    how can firebug tell me, which is the rigth element?

    rich:tree creates something like this:

    <form id="profileTreeFormId">
    <!-- root -->
    <div id="profileTreeFormId:profileTreeId:1::_defaultNodeFace:childs" class="...">
     <table class="..." id="profileTreeFormId:profileTreeId:1:1::_defaultNodeFace">
     <tbody>
     <tr id="profileTreeFormId:profileTreeId:1:1::_defaultNodeFace:mainRow" onclick=" ">
     <td class="..." id="profileTreeFormId:profileTreeId:1:1::_defaultNodeFace:handles">
     <div>
     <img alt="" class="..." id="profileTreeFormId:profileTreeId:1:1::_defaultNodeFace:handle:img" src="/.../spacer.gif.jsf" />
     <input class="..." id="profileTreeFormId:profileTreeId:1:1::_defaultNodeFaceNodeExpanded" name="profileTreeFormId:profileTreeId:1:1::_defaultNodeFaceNodeExpanded" type="hidden" value="true" />
     </div>
     </td>
     <td class="..." id="profileTreeFormId:profileTreeId:1:1::_defaultNodeFace:icon"
     rich:ajaxselectedlistener="ajax_selected_listener_flag"
     rich:draggableoptions="{'parameters':{'dragSourceId':'profileTreeFormId:profileTreeId:1:1::_defaultNodeFace','profileTreeFormId:profileTreeId:1:1::_defaultNodeFace':'profileTreeFormId:profileTreeId:1:1::_defaultNodeFace'} } "
     rich:dropzoneoptions="{} ">
     <img class="..." src="icon.gif" />
     </td>
     <td class="..." id="profileTreeFormId:profileTreeId:1:1::_defaultNodeFace:text" rich:highlightedclass="..." rich:selectedclass="...">
     <span id="profileTreeFormId:profileTreeId:1:1::_defaultNodeFaceOutput">OutputLeaf</span>
     </td>
     </tr>
     </tbody>
     </table>
     <div id="profileTreeFormId:profileTreeId:1:1::_defaultNodeFace:childs" style="display: none;" class="..."/>
    
    <!-- Some more Leafs -->
    </div>
    </form>
    


    So i tried to focus on the HtmlSpan element "OutputLeaf" and to call the click method, but nothing happened ,-|

    when i debug the generated code with firebug, i can see a variable "event" which has a attribute "selectedNode" and this attribute got the corresponding id to the span element mentioned before ... so what i'm doing wrong?
    momentary i'm thick as a brick ,-(

    thanks
    hiro

  • 3. Re: test rich:tree click
    Stan Silvert Master

    Firebug can log the events. So you set up the logging then you manually click on the browser and see what event was fired and what the target was.

    I see you have some drag and drop stuff in there. JSFUnit can't test RichFaces drag and drop right now because of a bug in HtmlUnit.

    We have some code in the Embedded JOPR tests that is used to get elements in a rich tree. This uses JSFUnit to test the JBoss Embedded Console. If you are familiar with that then you are familiar with the navigation tree on the left side of the screen.

    Some of the methods in this class might be helpful to you:
    http://anonsvn.jboss.org/repos/embjopr/trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java

    Stan

  • 4. Re: test rich:tree click
    Dont Mind Newbie

    finally i got the problem solved ...

    i just set up the webclient as follows:

    WebClientSpec wcSpec = new WebClientSpec("/login.jsf");
    WebClient webClient = wcSpec.getWebClient();
    webClient.setJavaScriptEnabled(true);
    JSFSession jsfSession = new JSFSession(wcSpec);
    


    with enabled java script everything is working fine ... and i also upgraded jsfunit to 1.1.0 but i don't know if it will work with 1.0.0


  • 5. Re: test rich:tree click
    Alphonse Bendt Newbie

    Hi,

     

    > JSFUnit can't test RichFaces drag and drop right now because of a bug in HtmlUnit.

     

    are there any news on this topic? is is possible to test drag and drop using the latest JSFUnit release (1.2.0) ?

    Our application uses rich:tree with rich:dropSupport.

     

    thanks in advance,

       Alphonse Bendt

  • 6. Re: test rich:tree click
    Stan Silvert Master

    Hi Alphonse,

     

    As far as I know, Drag and Drop for RichFaces is still broken in HtmlUnit.  Here is the bug:

    http://sourceforge.net/tracker/?func=detail&atid=448266&aid=2013417&group_id=47038

     

    If you talk to the HtmlUnit guys and ask real nice, maybe they will fix it. 

     

    Stan

  • 7. Re: test rich:tree click
    Alphonse Bendt Newbie

    Hello Stan,

     

    thanks.

     

    I asked on the HtmlUnit list. Does not look too good: http://marc.info/?l=htmlunit-user&m=127669222921586&w=2

     

    Alphonse

  • 8. Re: test rich:tree click
    Alphonse Bendt Newbie

    Hi Stan,

     

    we decided to contract one of the HtmlUnit developers to fix the issue. Currently Marc Guillemot (http://mguillem.wordpress.com/) is working on it. I'll keep you informed on any progress.

     

    regards,

       Alphonse

  • 9. Re: test rich:tree click
    Alphonse Bendt Newbie

    Hi Stan,

     

    Marc was successful! Actually it was not a bug in HtmlUnit. See the Ticket for details.

    Is there any work on JSFUnit necessary to actually use the Drag'n Drop?

     

    regards,

       Alphonse

  • 10. Re: test rich:tree click
    Stan Silvert Master

    You can use the plain HTMLUnit code as Marc shows.  I'll look into changing the RichFacesClient to make it easier for JSFUnit users.  However, I won't be able to do it until next week at the earliest.

     

    Stan

  • 11. Re: test rich:tree click
    Stan Silvert Master

    FYI.  I've fixed the RichFacesClient for JSFUnit 1.3.  You will be able to call:

     

    /**
        * Drag a component with rich:dragSupport to a component with rich:dropSupport.
        *
        * @param dragComponentID The JSF component ID or a suffix of the client ID
        *                        for the rich:dragSupport component.
        * @param dropTargetComponentID The JSF component ID or a suffix of the client ID
        *                              for the target rich:dropSupport component.
        *
        * @throws IOException if there is a problem submitting the form
        * @throws ComponentIDNotFoundException if the component can not be found
        * @throws DuplicateClientIDException if more than one client ID matches the
        *                                    componentID suffix
        */
       public void dragAndDrop(String dragComponentID, String dropTargetComponentID)

     

     

    Does that look helpful?

     

    Stan