0 Replies Latest reply on Aug 3, 2007 9:33 AM by fabmars

    Creating a custom component that uses a4j:jsfunction

    fabmars

      Hi

      I'm currently building an ajax enabled file upload component.
      this is related to this topic :
      http://jboss.com/index.html?module=bb&op=viewtopic&t=105534

      Well I took Tomahawk's code and used the method descripbed here :
      http://developer.apple.com/internet/webcontent/iframe.html

      My file upload component needs to render a button in addition to the file upload one, this is easy to do.

      The problem is that I needed to trigger some reRendering when the upload is finished. For that I rendered a HtmlAjaxFunction too, which actually generated the js call well, but the AjaxScript script link wouldn't be rendered in the page header...

      After thought, this is normal since script links are obviously rendered at the begining of the renderView, and my HtmlAjaxFunction is not in the tree during the header rendering.

      This led me to embed this HtmlAjaxFunction as a child of my custom HtmlInputFileUpload component so that the view would be aware of it at the beginign of renderView.

      This is as simple as instanciating a new HtmlAjaxFunction into my custom upload component and add it to its children using a getChildren().add(myEmbeddedHtmlAjaxFunction);
      I'm also including this embedded component's name & reRender attributes in the saveState/renderState of my custom component.

      The page renders well, but when I upload something with my component, I get an ArrayIndexOurOfBoundsException. If I don't add the jsfunction to my component's children, the exception doesn't occur (and of course the functionality isn't delivered because the jsFunction is no longer rendered)

      My question is : what did I forget ? I'm not even sure of what more I should do ?

      java.lang.ArrayIndexOutOfBoundsException: 1
       at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1040)
       at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1044)
       at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1044)
       at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1044)
       at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:336)
       at org.ajax4jsf.framework.ajax.AjaxStateManager.restoreView(AjaxStateManager.java:83)
       at com.sun.faces.application.ViewHandlerImpl.restoreView(ViewHandlerImpl.java:250)
       at com.sun.facelets.FaceletViewHandler.restoreView(FaceletViewHandler.java:310)
       at org.ajax4jsf.framework.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:116)
       at org.ajax4jsf.framework.ajax.AjaxViewHandler.restoreView(AjaxViewHandler.java:150)
       at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:177)
       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:245)
       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:110)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:213)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
       at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
       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:210)
       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.ErrorReportValve.invoke(ErrorReportValve.java:117)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
       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:685)
       at java.lang.Thread.run(Thread.java:595)