1 Reply Latest reply on Jul 25, 2006 7:37 AM by Pete Muir

    Need help with using ValueChangeEvent and SEAM

    Sean Burns Newbie

      I have a simple application that has a radio box and displays the value of the radio box to the screen. Everything seems to be working except when I browse away from that page and then browse back I get and Exception.

      <h:form>
       <h:selectOneRadio
       value="#{advancedSearch.currentType}"
       valueChangeListener="#{advancedSearch.typeSelected}"
       immediate="true"
       onclick="submit()"
       >
       <f:selectItems value="#{searchTypeList}" />
       </h:selectOneRadio>
       <h:outputText value="#{advancedSearch.currentType.label}"/>
       </h:form>


      and the code is



      @Stateless()
      @Name("advancedSearch")
      public class AdvancedSearchBean implements AdvancedSearchLocal {
      
       private SelectItem currentType;
      
       @Out
       private List<SelectItem> searchTypeList;
      
       @In
       private FacesContext facesContext;
      
       @Factory("searchTypeList")
       public void loadList() {
       setSearchTypeList(new ArrayList());
       getSearchTypeList().add(new SelectItem("1","1"));
       getSearchTypeList().add(new SelectItem("2","2"));
       }
      
       public void typeSelected(ValueChangeEvent event) {
       String value = (String) event.getNewValue();
       if ("1".equals(value)) {
       currentType = getSearchTypeList().get(0);
       } else if ("2".equals(value)) {
       currentType = getSearchTypeList().get(1);
       }
       //Not sure if this line is needed, it work without it
       facesContext.renderResponse();
       }
      
       public SelectItem getCurrentType() {
       return currentType;
       }
      
       public void setCurrentType(SelectItem currentType) {
       this.currentType = currentType;
       }
      
       public List<SelectItem> getSearchTypeList() {
       return searchTypeList;
       }
      
       public void setSearchTypeList(List<SelectItem> searchTypeList) {
       this.searchTypeList = searchTypeList;
       }
      }
      



      the exception is
      08:06:05,616 ERROR [STDERR] Jul 25, 2006 8:06:05 AM com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Error Rendering View[/search.xhtml]
      java.lang.IllegalArgumentException: Value is no String and component _id27:_id28with path: {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /search.xhtml][Class: javax.faces.component.html.HtmlForm,Id: _id27][Class: javax.faces.component.html.HtmlSelectOneRadio,Id: _id28]} does not have a Converter
       at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getConvertedStringValue(RendererUtils.java:536)
       at org.apache.myfaces.shared_impl.renderkit.html.HtmlRadioRendererBase.encodeEnd(HtmlRadioRendererBase.java:93)
       at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:536)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:242)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:239)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:239)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:580)
       at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:384)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       at java.lang.Thread.run(Thread.java:595)
      08:06:05,616 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
      java.lang.IllegalArgumentException: Value is no String and component _id27:_id28with path: {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /search.xhtml][Class: javax.faces.component.html.HtmlForm,Id: _id27][Class: javax.faces.component.html.HtmlSelectOneRadio,Id: _id28]} does not have a Converter
       at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getConvertedStringValue(RendererUtils.java:536)
       at org.apache.myfaces.shared_impl.renderkit.html.HtmlRadioRendererBase.encodeEnd(HtmlRadioRendererBase.java:93)
       at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:536)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:242)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:239)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:239)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:580)
       at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:384)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       at java.lang.Thread.run(Thread.java:595)
      08:06:25,276 ERROR [STDERR] Jul 25, 2006 8:06:25 AM com.sun.facelets.FaceletViewHandler handleRenderException
      



      Any help at all? am I think I am doing something fundementally wrong with the life cycle, buy I am not sure what?

      Thanks Sean.

        • 1. Re: Need help with using ValueChangeEvent and SEAM
          Pete Muir Master

          The 'value' of the selectOne is not a SelectItem but a String (unless a converter is supplied). You might want to look at one of the @SelectItems annotations that will create the SelectItem list for you (based on a list of Strings).

          @Stateless()
          @Name("advancedSearch")
          public class AdvancedSearchBean implements AdvancedSearchLocal {
          
           private String currentType;
          
           @Out
           private List<SelectItem> searchTypeList;
          
           @In
           private FacesContext facesContext;
          
           @Factory("searchTypeList")
           public void loadList() {
           setSearchTypeList(new ArrayList());
           getSearchTypeList().add(new SelectItem("1","1"));
           getSearchTypeList().add(new SelectItem("2","2"));
           }
          
           public void typeSelected(ValueChangeEvent event) {
           String value = (String) event.getNewValue();
           if ("1".equals(value)) {
           currentType = getSearchTypeList().get(0);
           } else if ("2".equals(value)) {
           currentType = getSearchTypeList().get(1);
           }
           //Not sure if this line is needed, it work without it
           facesContext.renderResponse();
           }
          
           public String getCurrentType() {
           return currentType;
           }
          
           public void setCurrentType(String currentType) {
           this.currentType = currentType;
           }
          
           public List<SelectItem> getSearchTypeList() {
           return searchTypeList;
           }
          
           public void setSearchTypeList(List<SelectItem> searchTypeList) {
           this.searchTypeList = searchTypeList;
           }
          }