5 Replies Latest reply on Aug 17, 2010 7:42 PM by John Franey

    uiComponent Map issues

    lholmquist Newbie

      I'm trying to use the Seam uiComponent map to find some components during a valuechangelistener,  but i am having an issue. 


      i have an input text tag with a value change listener(onblur) that goes to a method.  when i try to access the uiComponent  i get this error


      Method threw 'java.lang.UnsupportedOperationException' exception.



      i'm using jboss 5.0.1 with seam 2.1.2


      any help would be appreciated.  i've been using the Seam in Action book by dan allen and it looks like my code is the same as his examples.



      Here is the facelet code:




       <h:form id="dateForm">Date 1:
      
                  <h:inputText id="statusId" value="#{hdIndexSearch.statusId}" valueChangeListener="#{pageBind.doValChange}">
                      <a:support event="onblur" bypassUpdates="true" ajaxSingle="true"/>
                  </h:inputText>





      Here is the action:




      @Name("pageBind")
      public class PageBinder {
      
      
          @In
          Map<String, UIComponent> uiComponent;
          
          
      
          public void doValChange(ValueChangeEvent e)
          {
                List<UIComponent> cList = new ArrayList<UIComponent>(uiComponent.values());
      
              UIComponent testComp = e.getComponent().findComponent("dateForm:statusId");
      
              System.out.println("stop");
      
          }



      Here is the error log





      10:57:14,444 ERROR [AjaxViewRoot] Error processing faces event for the component dateForm:statusId
      javax.faces.event.AbortProcessingException: /push/other.xhtml @21,120 valueChangeListener="#{pageBind.doValChange}": java.lang.UnsupportedOperationException
           at javax.faces.event.MethodExpressionValueChangeListener.processValueChange(MethodExpressionValueChangeListener.java:93)
           at javax.faces.event.ValueChangeEvent.processListener(ValueChangeEvent.java:134)
           at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:771)
           at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:329)
           at org.ajax4jsf.component.AjaxViewRoot.broadcastEventsForPhase(AjaxViewRoot.java:302)
           at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:261)
           at org.ajax4jsf.component.AjaxViewRoot.processValidators(AjaxViewRoot.java:463)
           at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
           at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
           at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
           at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:905)
           at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:595)
           at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2036)
           at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.UnsupportedOperationException
           at org.jboss.seam.faces.UiComponent$1.entrySet(UiComponent.java:48)
           at java.util.AbstractMap.size(AbstractMap.java:67)
           at java.util.AbstractMap$2.size(AbstractMap.java:370)
           at java.util.AbstractCollection.toArray(AbstractCollection.java:119)
           at java.util.ArrayList.<init>(ArrayList.java:131)
           at stuff.PageBinder.doValChange(PageBinder.java:63)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
           at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
           at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
           at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
           at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
           at stuff.PageBinder_$$_javassist_seam_6.doValChange(PageBinder_$$_javassist_seam_6.java)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
           at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)
           at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
           at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
           at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
           at org.jboss.seam.el.OptionalParameterMethodExpression.invoke(OptionalParameterMethodExpression.java:39)
           at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
           at javax.faces.event.MethodExpressionValueChangeListener.processValueChange(MethodExpressionValueChangeListener.java:91)
           ... 53 more




        • 1. Re: uiComponent Map issues
          John Franey Novice

          Doctor, Doctor!  Its hurts when I do this!


          Then, don't do that.


          uiComponent.values call uiComponent.entrySet.  The seam source code shows the implementation of uiComponent's entrySet method has a single line:
            throw new UnsupportedOperationException();


          Don't call uiComponent.values.

          • 2. Re: uiComponent Map issues
            John Franey Novice

            Sorry, fix that.  entrySet does indeed throw the exception, but it is not directly called by uiComponent.values.  The ArrayList constructor calls entrySet.

            • 3. Re: uiComponent Map issues
              lholmquist Newbie

              thanks for the explanation.  if i try to just get a particular value with uiComponent.get(value:thing)  it works fine.  the debugger in IntelliJ was also showing the same error,   i was just trying to inspect the different values while i was playing around with a few things.  not critical to the actual functionality of the project. 

              • 4. Re: uiComponent Map issues
                lholmquist Newbie

                Just a follow up question. Will these methods ever be implemented?  how would one go about getting a list of the values stored in this map?

                • 5. Re: uiComponent Map issues
                  John Franey Novice

                  Ok.  Good question.  I didn't know myself.  I'm not a Seam developer, just getting feet wet too, I think I'm up to my ankles.


                  Anyway, I took a look at the source code for UiComponent.  It is not a Container.  It is only a map like interface to the components lookup of the current view.  Take a look at the code, please.  Google found me version 2.0, which is close enough, I hope, to the version you are using.  It puts a facade in front of UiViewRoot.findComponent(String id).  I took a look at the UiViewRoot javadoc.  UiViewRoot inherits listChildren() from UiComponentBase.


                  In your listener, do the same thing as in the UiComponent.get method:  something like:


                   
                    FacesContext context = FacesContext.getCurrentContext();
                    UIViewRoot viewRoot = context.getViewRoot();
                    List<javax.faces.component.UiComponent> children = viewRoot.getChildren();
                  
                    // recurse through children.
                  



                  I make the assumption that the only purpose of 

                  org.jboss.seam.faces.UiComponent

                  is for convenience, not as a meaty alternative to the UiViewRoot api.