10 Replies Latest reply: Jun 13, 2008 12:48 PM by Stan Silvert RSS

How do I clickCommandLink a link in datatable

Jane Zhen Newbie

I have a datatable that each row has a commandlink. I want to click on these commandlinks one by one to see if the contents are loaded correctly. But I keep getting "No component ID was found for profileTabForm:tab0:allProfileTab:allProfileTable:0:profileName" error. I know "profileTabForm:tab0:allProfileTab:allProfileTable:0:profileName" is actually a clientid. however I don't know what to put in as the component id.

I have a form (profileTabForm), then a tabbedpane, then a datatable, and then finally the row (0) and commandLink id (profileName).

thanks in advance for any helps

Jane

  • 1. Re: How do I clickCommandLink a link in datatable
    Jane Zhen Newbie

    The error was because I was mistakenly loading a different page :)

    However, when I load the right page, I still get

    java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(Unknown Source) at java.lang.String.substring(Unknown Source) at org.jboss.jsfunit.facade.JSFClientSession.setMojarraCmdLinkParams(JSFClientSession.java:546) at org.jboss.jsfunit.facade.JSFClientSession.setCmdLinkParams(JSFClientSession.java:520) at org.jboss.jsfunit.facade.JSFClientSession.clickCommandLink(JSFClientSession.java:473) at com.hp.ed.jsfunittest.JSFUnitTest.testClickingCommandLinks(JSFUnitTest.java:75)

    I guess the component id with a row index "0" is not recognized correctly, is it?

    How am I do this then? or is it even possible?

    tahnks
    Jane

  • 2. Re: How do I clickCommandLink a link in datatable
    Stan Silvert Master

    By any chance are you using MyFaces 2.0? CommandLink support for MyFaces 2.0 isn't there just yet unless you try the new HtmlUnit-based code.

    Stan

  • 3. Re: How do I clickCommandLink a link in datatable
    Jane Zhen Newbie

    Hi Stan,

    As I posted in another thread, I'm using Tomahawk 1.1. yes, I'm following your advice to try out the htmlunit + beta 2 build. http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4156095
    Reply to topic

    Thank you
    Jane

  • 4. Re: How do I clickCommandLink a link in datatable
    Stan Silvert Master

     

    "zhen_jane" wrote:
    Hi Stan,

    As I posted in another thread, I'm using Tomahawk 1.1. yes, I'm following your advice to try out the htmlunit + beta 2 build. http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4156095
    Reply to topic

    Thank you
    Jane


    I'm confused. The stack trace you posted is using org.jboss.jsfunit.facade.JSFClientSession. But the new HtmlUnit code uses a different package. Namely, org.jboss.jsfunit.jsfsession.JSFClientSession.

    Also, the HtmlUnit stuff is not in the Beta 2 build. You have to build from SVN to see that.

    Stan

  • 5. Re: How do I clickCommandLink a link in datatable
    Jane Zhen Newbie

    Hi Stan,

    Yes, this post was posted before I saw the other thread to know there is another jsfsession.JSFClientSession and htmlunit + beta 2.
    So basically, I was using facade.JSFClientSession and tried to click a commandlink in Tomahawk tag lib and got the previous stack trace.
    Then I followed your advice to build and try the jsfsession.JSFClientSession + htmlunit + beta 2 solution. Here is the result.

    Well, it's not totally working yet..because we use yahoo yui javascript code and that is causing problems:

    Wrapped com.gargoylesoftware.htmlunit.ScriptException: Wrapped java.lang.ClassCastException: com.gargoylesoftware.htmlunit.html.HtmlPage (http://localhost/myapp/xxx/js/yui/build/yahoo-dom-event/yahoo-dom-event.js#7) (http://localhost/myapp/xxx/js/forceinFW.js#54)" type="org.apache.cactus.internal.client.ServletExceptionWrapper">======= EXCEPTION START ======== Exception class=[org.mozilla.javascript.WrappedException] com.gargoylesoftware.htmlunit.ScriptException: Wrapped com.gargoylesoftware.htmlunit.ScriptException: Wrapped java.lang.ClassCastException: com.gargoylesoftware.htmlunit.html.HtmlPage (http://localhost/myapp/xxx/js/yui/build/yahoo-dom-event/yahoo-dom-event.js#7) (http://localhost/myapp/xxx/js/forceinFW.js#54) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:553) at org.mozilla.javascript.Context.call(Context.java:499) at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:511) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:436) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:411) at
    ..

    Is there a way to turn off javascript error checking/exception throwing because I heard this is a solution ? I know there is a function in httpunit (HttpUnitOptions.setExceptionsThrownOnScriptError(false)) for that, but since we are using htmlunit.....

    Also, one wierd thing I noticed is although I was using jsfsession/htmlunit, at the beginning of my program, I'm still using WebConversation to set up the username and password and start off the SSL session:

    webConv = WebConversationFactory.makeWebConversation();
    webConv.setAuthorization("administrator", "password");

    Isn't WebConversation a HTTPUnit class (com.meterware.httpunit.WebConversation)? Is it OK to use httpunit and htmlunit in this mixed way?

    thanks for any feedback for dealing with this javascript exception throwing

    jane

  • 6. Re: How do I clickCommandLink a link in datatable
    Stan Silvert Master

     

    "zhen_jane" wrote:

    Is there a way to turn off javascript error checking/exception throwing because I heard this is a solution ? I know there is a function in httpunit (HttpUnitOptions.setExceptionsThrownOnScriptError(false)) for that, but since we are using htmlunit.....

    I don't know off hand. You can search the HtmlUnit site or ask the question on the HtmlUnit mailing list.
    "zhen_jane" wrote:

    Also, one wierd thing I noticed is although I was using jsfsession/htmlunit, at the beginning of my program, I'm still using WebConversation to set up the username and password and start off the SSL session:

    webConv = WebConversationFactory.makeWebConversation();
    webConv.setAuthorization("administrator", "password");

    Isn't WebConversation a HTTPUnit class (com.meterware.httpunit.WebConversation)? Is it OK to use httpunit and htmlunit in this mixed way?

    You shouldn't mix them. Right now, they are both available because we are in transition. To do the equivalent thing with HtmlUnit, you need to call WebConversationFactory.makeWebClient() instead of WebConversationFactory.makeWebConversation().

    Then it looks like you will need to use WebClient.setCredentialsProvider(), and pass the WebClient to the constructor of JSFSesion. I haven't tried this myself yet, so please let us know how it turns out.

    Stan



  • 7. Re: How do I clickCommandLink a link in datatable
    Jane Zhen Newbie

    Hi Stan,

    I learned there are other cases when using HTMLUnit and JSFUnit together, a ClassCastException is thrown. I tried to use HTMLUnit alone and the javascript worked fine.

    If you need the whole stack trace, I can reproduce it and post here.

    The authentication thing, yes, you were quite right. I used following code, and it seemed working (as I always got those errors so I wasn't sure what has been the reason for that)

    webClient.setCredentialsProvider(new CredentialsProvider(){
    public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy) {
    return new UsernamePasswordCredentials("admin", "password");
    }
    });
    JSFSession jsfSession = new JSFSession(webClient, url);


  • 8. Re: How do I clickCommandLink a link in datatable
    Jane Zhen Newbie

    Sorry Stan, actually the

    JSFSession jsfSession = new JSFSession(webClient, url);

    statement threw following exception:

    error message="null" type="org.apache.cactus.internal.client.ServletExceptionWrapper">
    java.lang.NullPointerException
    at org.jboss.jsfunit.framework.FacesContextBridge.getCurrentInstance(FacesContextBridge.java:54)
    at org.jboss.jsfunit.jsfsession.ClientIDs.(ClientIDs.java:60)
    at org.jboss.jsfunit.jsfsession.JSFServerSession.pageCreated(JSFServerSession.java:162)
    at org.jboss.jsfunit.jsfsession.JSFUnitPageCreator.notifyListeners(JSFUnitPageCreator.java:64)
    at org.jboss.jsfunit.jsfsession.JSFUnitPageCreator.createPage(JSFUnitPageCreator.java:55)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:445)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:352)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:402)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:389)
    at org.jboss.jsfunit.jsfsession.JSFSession.(JSFSession.java:108)
    at com.hp.ed.jsfunittest.JSFUnitTest.testClickingCommandLinks(JSFUnitTest.java:78)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
    at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)
    at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
    at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:224)
    at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
    at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101)
    at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:224)
    at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
    at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72)
    at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:224)
    at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:122)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
    at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at com.hp.ov.cwc.web.jsf.CwcExtensionsFilter.doFilter(CwcExtensionsFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at com.hp.ed.webui.ConfigUIFilter.doFilter(ConfigUIFilter.java:24)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReport
    Valve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Unknown Source)

    cheers

    Jane

  • 9. Re: How do I clickCommandLink a link in datatable
    Stan Silvert Master

    Hi Jane,

    I'm working on this now. I've been needing to update the security tests anyway. So I'll try this myself. Thanks for your patience.

    Stan

  • 10. Re: How do I clickCommandLink a link in datatable
    Stan Silvert Master

    I've made some big changes, including code for doing authentication.

    See http://jira.jboss.com/jira/browse/JSFUNIT-99

    Thanks for your feedback,

    Stan