3 Replies Latest reply on Mar 14, 2007 1:53 PM by Rob Jellinghaus

    I try a4j-dropDownBoxes with jsf/seam but I can´t do it to w

    Aristides Santos Newbie

      Sorry for my telegrafic english but I try a lot but and I can´t do it to work....my fragment facelets:

      <tr>
       <td class="cntForm">Estado (UF):</td>
       <td class="cntForm">
       <h:panelGroup>
       <h:selectOneMenu value="#{buscaAction.estado}"
       converter="#{estados.converter}">
       <f:selectItem itemLabel="" itemValue="#{estados.nullEstado}" />
       <f:selectItems value="#{estados.estados}" />
       <a4j:support event="onchange" action="#{buscaAction.fazNada}"
       ajaxSingle="true" reRender="Option1" />
       </h:selectOneMenu>
       </h:panelGroup>
       </td>
       </tr>
       <tr>
       <td class="cntForm">Cidade:</td>
       <td class="cntForm">
       <h:panelGroup id="Option1">
       <h:selectOneMenu value="#{visitante.cidadeByCidadeId}"
       converter="#{cidades.converter}">
       <f:selectItem itemLabel="" itemValue="#{cidades.nullCidade}" />
       <f:selectItems value="#{cidades.cidades}" />
       <a4j:support event="onchange"/>
       </h:selectOneMenu>
       </h:panelGroup>
      
       </td>
       </tr>
      I can to submit page without erros with this three web_beans:
      @Stateful
      @Name("estados")
      @Scope(ScopeType.EVENT)
      public class EstadosBean
       implements Estados,
       Serializable
      {
       List<Estado> estados;
       Map<String,Estado> estadoMap;
      
       @PersistenceContext
       EntityManager em;
      
       @Create
       public void loadData() {
      
       estados = em.createQuery("select c from Estado c")
       .setHint("org.hibernate.cacheable", true)
       .getResultList();
      
       Map<String,Estado> results = new TreeMap<String,Estado>();
      
       for (Estado estado: estados) {
       results.put(estado.getEstadoSigla(),estado);
       }
      
       estadoMap = results;
       }
      
       public Map<String,Estado> getEstados() {
       return estadoMap;
       }
      
       public Converter getConverter() {
       return new EstadoConverter(estados);
       }
      
       public Estado getNullEstado() {
       return new Estado();
       }
      
       static public class EstadoConverter
       implements Converter,
       Serializable
       {
       List<Estado> estados;
      
       public EstadoConverter(List<Estado> estados) {
       this.estados = estados;
       }
      
       public String getAsString(FacesContext facesContext,
       UIComponent component,
       Object obj)
       {
       if (obj == null) return null;
      
       Estado estado = (Estado) obj;
       String val = String.valueOf(estado.getEstadoSigla());
      
       return val;
       }
      
       public Object getAsObject(FacesContext facesContext,
       UIComponent component,
       String str)
       throws ConverterException
       {
       if (str == null || str.length()==0) {
       return null;
       }
      
       for (Estado estado : estados) {
       if (estado.getEstadoSigla() == str) {
       return estado;
       }
       }
      
       return null;
       }
       }
      
       @Remove @Destroy
       public void destroy() {}
      }
      
      @Stateful
      @Name("cidades")
      @Scope(ScopeType.EVENT)
      public class CidadesBean
       implements Cidades,
       Serializable
      {
       @In
       BuscaAction buscaAction;
      
       List<Cidade> cidades;
       List<Cidade> selecionadas;
       Map<String,Cidade> cidadeMap;
      
       @PersistenceContext
       EntityManager em;
      
       @Create
       public void loadData() {
       cidades = em.createQuery("select c from Cidade c" )
       .setHint("org.hibernate.cacheable", true)
       .getResultList();
      
       Map<String,Cidade> results = new TreeMap<String,Cidade>();
      
       for (Cidade cidade: cidades) {
       results.put(cidade.getCidadeNome(),cidade);
       }
      
       selecionadas = cidades;
       cidadeMap = results;
       }
      
       public void selecionarCidades() {
       System.out.println(buscaAction.getEstado());
       if (buscaAction.getEstado().getEstadoSigla() != null)
       for (Cidade cidade: cidades) {
       System.out.println(cidade.getEstado().getEstadoSigla());
       System.out.println(buscaAction.getEstado().getEstadoSigla());
       if (cidade.getEstado().getEstadoSigla().equals(buscaAction.getEstado().getEstadoSigla()))
       selecionadas.add(cidade);
       }
      
       }
      
       public Map<String,Cidade> getCidades() {
       return cidadeMap;
       }
      
       public Converter getConverter() {
       return new CidadeConverter(selecionadas);
       }
      
       public Cidade getNullCidade() {
       return new Cidade();
       }
      
       static public class CidadeConverter
       implements Converter,
       Serializable
       {
       List<Cidade> cidades;
      
       public CidadeConverter(List<Cidade> cidades) {
       this.cidades = cidades;
       }
      
       public String getAsString(FacesContext facesContext,
       UIComponent component,
       Object obj)
       {
       if (obj == null) return null;
      
       Cidade cidade = (Cidade) obj;
       String val = String.valueOf(cidade.getCidadeId());
      
       return val;
       }
      
       public Object getAsObject(FacesContext facesContext,
       UIComponent component,
       String str)
       throws ConverterException
       {
       if (str == null || str.length()==0) {
       return null;
       }
      
       int id = Integer.valueOf(str).intValue();
       for (Cidade cidade : cidades) {
       if (cidade.getCidadeId() == id) {
       return cidade;
       }
       }
      
       return null;
       }
       }
      
       @Remove @Destroy
       public void destroy() {}
      }
      
      @Stateful
      @Name("buscaAction")
      @Scope(SESSION)
      public class BuscaActionBean implements BuscaAction {
      /*
       @PersistenceContext
       EntityManager em;
      */
       Estado estado;
      
       List<Cidade> cidades;
       Map<String,Cidade> cidadeMap;
      
       public void setEstado(Estado estado) {
       this.estado = estado ;
       }
      
       public Estado getEstado() {
       return estado;
       }
      
       public void fazNada() {}
      
       @Destroy
       @Remove
       public void destroy() {}
      
      }
      
      But if I modify this
      <a4j:support event="onchange" action="#{buscaAction.fazNada}"
      for this
      <a4j:support event="onchange" action="#{cidades.selecionarCidades}"
      I receive this error (debug.xml):
      xception during request processing: java.lang.NullPointerException:
      
      br.com.qrx.CidadesBean.selecionarCidades(CidadesBean.java:60)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      java.lang.reflect.Method.invoke(Unknown Source)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
      org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
      org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:37)
      org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
      org.jboss.seam.interceptors.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:47)
      org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
      org.jboss.seam.interceptors.BusinessProcessInterceptor.aroundInvoke(BusinessProcessInterceptor.java:51)
      org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
      org.jboss.seam.interceptors.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:27)
      org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
      org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
      org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:53)
      sun.reflect.GeneratedMethodAccessor218.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      java.lang.reflect.Method.invoke(Unknown Source)
      org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
      org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:46)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
      org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
      org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:203)
      org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:98)
      $Proxy130.selecionarCidades(Unknown Source)
      br.com.qrx.Cidades$$FastClassByCGLIB$$8fbbcead.invoke(<generated>)
      net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
      org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:45)
      org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:74)
      org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
      org.jboss.seam.interceptors.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:40)
      org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
      org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
      org.jboss.seam.intercept.ClientSideInterceptor.intercept(ClientSideInterceptor.java:52)
      org.jboss.seam.intercept.Proxy$$EnhancerByCGLIB$$27af74c6.selecionarCidades(<generated>)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      java.lang.reflect.Method.invoke(Unknown Source)
      com.sun.el.parser.AstValue.invoke(AstValue.java:151)
      com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
      com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
      com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:69)
      org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
      org.ajax4jsf.framework.ajax.AjaxActionComponent.broadcast(AjaxActionComponent.java:88)
      org.ajax4jsf.framework.ajax.AjaxViewRoot.processEvents(AjaxViewRoot.java:274)
      org.ajax4jsf.framework.ajax.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:250)
      org.ajax4jsf.framework.ajax.AjaxViewRoot.processApplication(AjaxViewRoot.java:405)
      org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:343)
      org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
      javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
      org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
      org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
      org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
      org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
      org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:75)
      org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:213)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
      org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      java.lang.Thread.run(Unknown Source)
      What am i wrong ? Aristides