1 2 Previous Next 18 Replies Latest reply on Jan 31, 2011 9:29 AM by ssilvert Go to original post
      • 15. Re: RichFaces and ajaxQueues
        blabno

        Stan, I'm testing and testing that naughty ajax and have to tell you that I haven't come up with 100% sure method yet. Here is what i'm using for now:

         

        {code}

        public class WebClientUtils {

         

            private static long defaultCheckInterval = 500;

            private static long defaultTimeout = 10000;

         

            public static long getDefaultCheckInterval() {

                return defaultCheckInterval;

            }

         

            public static void setDefaultCheckInterval(long defaultCheckInterval) {

                WebClientUtils.defaultCheckInterval = defaultCheckInterval;

            }

         

            public static long getDefaultTimeout() {

                return defaultTimeout;

            }

         

            public static void setDefaultTimeout(long defaultTimeout) {

                WebClientUtils.defaultTimeout = defaultTimeout;

            }

         

            public static int waitForJSJob(WebClient webClient) {

                return waitForJSJob(webClient, webClient.waitForBackgroundJavaScript(10) - 1, defaultCheckInterval, defaultTimeout);

            }

         

            public static int waitForJSJob(WebClient webClient, int initialJobCount) {

                return waitForJSJob(webClient, initialJobCount, defaultCheckInterval, defaultTimeout);

            }

         

            public static int waitForJSJob(WebClient webClient, int initialJobCount, long timeout) {

                return waitForJSJob(webClient, initialJobCount, defaultCheckInterval, timeout);

            }

         

            public static int waitForJSJob(WebClient webClient, int initialJobCount, long checkInterval, long timeout) {

                int jobs;

                long startTime = System.currentTimeMillis();

                do {

                    jobs = webClient.waitForBackgroundJavaScript(checkInterval);

                    if (startTime + timeout < System.currentTimeMillis()) {

                        throw new RuntimeException("Number of JavaScript jobs doesn't drop to initial level for 10000 seconds. It's memory leak in your JavaScript rather then request taking so long!");

                    }

                } while (jobs > initialJobCount);

                System.out.println("Waiting took: " + (System.currentTimeMillis() - startTime) + "ms");

                return jobs;

            }

         

            /**

             * Returns list of suggestions from rich:suggestionBox

             *

             * @param suggestion suggestionBox element

             * @param column     column of suggestionBox to extract text from

             * @return list of suggestions

             */

            public static Map<String, HtmlTableCell> getSuggestions(HtmlElement suggestion, int column) {

                final Map<String, HtmlTableCell> suggestions = new HashMap<String, HtmlTableCell>();

                final HtmlElement suggestElement = suggestion.getElementById(suggestion.getId() + ":suggest");

                @SuppressWarnings("unchecked")

                final DomNodeList<HtmlElement> suggestionRows = suggestElement.getElementsByTagName("tr");

                for (HtmlElement row : suggestionRows) {

                    @SuppressWarnings("unchecked")

                    final DomNodeList<HtmlElement> cells = row.getElementsByTagName("td");

                    final HtmlTableCell cell = (HtmlTableCell) cells.get(column + 1);

                    suggestions.put(cell.asText(), cell);

                }

                return suggestions;

            }

        }

        {code}

        • 16. RichFaces and ajaxQueues
          ssilvert

          Bernard,

           

          Have you signed the CLA?  When you think the code meets the standard of "general usefulness"  I'd like to include it in the distribution.

          https://cla.jboss.org/login.seam?cid=268

           

          We could put getSuggestions() into the RichFacesClient.  I think the rest would go in JSFClientSession.  Then you wouldn't need to pass in WebClient.  What do you think?

           

          Stan

          • 17. RichFaces and ajaxQueues
            blabno

            I've signed CLA. In my project we have separate subproject forquickly writing tests in pure htmlunit. This speeds development up(even hot deploy of JSFUnit tests is to slow for us). So we write those tests and put common stuff into WebClientUtils. Then we use that class in our project where we have JSFUnitUtils which delegates most work to WebClientUtils.

            I think that could be some solution. Such subproject could be called htmlunit4richfaces.

            But your idea sounds also good for me.

            • 18. RichFaces and ajaxQueues
              ssilvert

              Great.  If there's more code you'd like to contribute let me know.  And if you'd like to become a comitter I'd be happy to let you fully join the project so you can contribute directly to SVN.

               

              Any htmlunit4richfaces code would fit nicely into the RichFacesClient submodule.  There's not that much code in there now.  It really needs to be built out more.

               

              Stan

              1 2 Previous Next