2 Replies Latest reply on Jun 15, 2009 4:11 PM by Rafael Espirito Santo

    ListShuttle and converter

    Rafael Espirito Santo Newbie

      Hi!!


      I´m new on Seam and have some problems to use the listShuttle Component.


      This is an fragment of xhtml page




      <s:decorate id="usuariosField" template="/layout/display.xhtml">
                          <ui:define name="label">#{messages['areaPesquisa.usuarios.label']}</ui:define>
                          <rich:listShuttle id="usuarios"  sourceCaptionLabel="#{messages['areaPesquisa.usuarios.tabela.fonte.label']}"
                                                var="_usuario" targetRequired="true" targetCaptionLabel="#{messages['areaPesquisa.usuarios.tabela.destino.label']}"
                                                targetValue="#{areaPesquisa.usuarioList}"
                                                sourceValue="#{administrarAreaPesquisaAction.listaUsuarios}"
                                                converter="#{usuarioConverter}">
                               <rich:column>
                                    <h:outputText value="#{_usuario.nome}" />
                               </rich:column>                      
                          </rich:listShuttle>
                     </s:decorate>



      If I do not use the @BypassInterceptor annotation JBoss launch an exception


      java.lang.RuntimeException: Could not create Component: usuarioConverter
              at org.jboss.seam.init.Initialization.addComponent(Initialization.java:1178)
              at org.jboss.seam.init.Initialization.installComponents(Initialization.java:1094)
              at org.jboss.seam.init.Initialization.init(Initialization.java:728)
              at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:35)
              at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3910)
              at org.apache.catalina.core.StandardContext.start(StandardContext.java:4393)
              at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:367)
              at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:146)
              at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:460)
              at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
              at org.jboss.web.deployers.WebModule.start(WebModule.java:96)
              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.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
              at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
              at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
              at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
              at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)
              at $Proxy36.start(Unknown Source)
              at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)
              at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)
              at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
              at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
              at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
              at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
              at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:286)
              at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
              at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
              at org.jboss.system.ServiceController.doChange(ServiceController.java:688)
              at org.jboss.system.ServiceController.start(ServiceController.java:460)
              at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:146)
              at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:104)
              at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:45)
              at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
              at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
              at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1210)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
              at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
              at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
              at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
              at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
              at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
              at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:545)
              at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:290)
              at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:221)
              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
              at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
              at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.IllegalStateException: Converter br.ufrj.cos.portalfees.session.usuario.UsuarioConverter must be annotated with @BypassInterceptors
              at org.jboss.seam.Component.registerConverterOrValidator(Component.java:330)
              at org.jboss.seam.Component.<init>(Component.java:257)
              at org.jboss.seam.Component.<init>(Component.java:206)
              at org.jboss.seam.init.Initialization.addComponent(Initialization.java:1162)
              ... 67 more



      The problem is that I can´t have access to EntityManager with Dependency Injection.


      How can I solve this problem (to hava access to EntityManager) or other whays to use the listShuttle with converter?


      This is the converter code


      @Name("usuarioConverter")
      @Converter
      @BypassInterceptors
      public class UsuarioConverter implements javax.faces.convert.Converter {
      
           @Logger
           private Log log;
           
           @In
           private EntityManager entityManager;
           
           @Override
           public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
                Usuario usuario = null;
                long id = Long.parseLong(arg2);
                
                if (entityManager != null) {
                     usuario = (Usuario) entityManager.createQuery("select u from Usuario u where u.id = ?").setParameter(1, id).getSingleResult();
                } else {
                     log.info("TA VINDO NULO!!");
                }
                
                return usuario;
           }
      
           @Override
           public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
                Usuario u = (Usuario) arg2;
                return Long.toString(u.getId());
           }
      
      }



      Thanks!












        • 1. Re: ListShuttle and converter
          Tim Evers Master

          Hi Rafael,


          I haven't tried this myself, but the following code should work if you need the Entity Manager in a SEAM bean annotated with @BypassInterceptors.


          Component.getInstance(EntityManager.class)
          



          Do you understand what the @BypassInterceptors is doing? If not read up in the SEAM docs about BypassInterceptors so you understand what's happening in your situation.

          • 2. Re: ListShuttle and converter
            Rafael Espirito Santo Newbie

            Hi!



            It works with this code


            @Transactional
                 public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
                      Usuario usuario = null;
                      long id = Long.parseLong(arg2);
                      
                      EntityManager entityManager = (EntityManager) Component.getInstance("entityManager");
                      
                      if (entityManager != null) {
                           entityManager.joinTransaction();
                           usuario = (Usuario) entityManager.createQuery("select u from Usuario u where u.id = ?").setParameter(1, id).getSingleResult();
                      } 
                      
                      return usuario;
                 }



            When I tried to use Component.getInstance(EntityManager.class) an exception was lauch.


            Thanks for the help!!