4 Replies Latest reply on Jun 13, 2007 1:18 AM by Anthony Whitford

    s:convertEntity with non-numeric @Id

    Anthony Whitford Newbie

      According to the documentation:


      The converter works with any entity which has an @Id annotation - either simple or composite.

      But if I try to use it with an Entity that has a String as the @Id, I get a NumberFormatException:
      java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
      java.lang.Integer.parseInt(Integer.java:447)
      java.lang.Integer.<init>(Integer.java:620)
      org.jboss.seam.ui.EntityConverter.getAsObject(EntityConverter.java:80)
      com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:152)
      

      So this would lead me to believe that it works only for numbers. Can this please be emphasized in the documentation?


      So what do I need to do? I guess I need to delcare my own converter? And then how do I get it wired in?

      Or could EntityConverter be enhanced to handle String @Id Entities? (Overload the get method in EntityConverterStore, and do some kind of class meta-data check in EntityConverter?)


        • 1. Re: s:convertEntity with non-numeric @Id
          Pete Muir Master

          It works with *any* object - take a look at the ui example.

          Post the whole stack trace. You are using 1.2.1.GA?

          • 2. Re: s:convertEntity with non-numeric @Id
            Anthony Whitford Newbie

            I'm using Seam 1.3.0.ALPHA. Here is the full stack trace:

            Caused by javax.servlet.ServletException with message: "For input string: "USD""

            javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:60)
            org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:55)
            org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:47)
            org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:55)
            org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:81)
            org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:55)
            org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:293)
            org.jboss.seam.web.AbstractAjax4jsfFilter.doFilter(AbstractAjax4jsfFilter.java:35)
            org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:55)
            org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:64)
            org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:55)
            org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:126)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
            org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
            org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
            org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
            org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
            org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
            org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
            org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
            org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
            org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
            org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
            java.lang.Thread.run(Thread.java:619)
            

            Caused by java.lang.NumberFormatException with message: "For input string: "USD""
            java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
            java.lang.Integer.parseInt(Integer.java:447)
            java.lang.Integer.<init>(Integer.java:620)
            org.jboss.seam.ui.EntityConverter.getAsObject(EntityConverter.java:80)
            com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:152)
            com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:197)
            com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:359)
            javax.faces.component.UIInput.getConvertedValue(UIInput.java:934)
            javax.faces.component.UIInput.validate(UIInput.java:860)
            javax.faces.component.UIInput.executeValidate(UIInput.java:1065)
            javax.faces.component.UIInput.processValidators(UIInput.java:666)
            javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
            javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
            javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
            javax.faces.component.UIForm.processValidators(UIForm.java:229)
            javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
            javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:662)
            org.ajax4jsf.framework.ajax.AjaxViewRoot.access$201(AjaxViewRoot.java:53)
            org.ajax4jsf.framework.ajax.AjaxViewRoot$3.invokeRoot(AjaxViewRoot.java:315)
            org.ajax4jsf.framework.ajax.JsfOneOneInvoker.invokeOnRegionOrRoot(JsfOneOneInvoker.java:53)
            org.ajax4jsf.framework.ajax.AjaxContext.invokeOnRegionOrRoot(AjaxContext.java:191)
            org.ajax4jsf.framework.ajax.AjaxViewRoot.processValidators(AjaxViewRoot.java:329)
            com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:100)
            com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
            com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
            javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:60)
            org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:55)
            org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:47)
            org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:55)
            org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:81)
            org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:55)
            org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:293)
            org.jboss.seam.web.AbstractAjax4jsfFilter.doFilter(AbstractAjax4jsfFilter.java:35)
            org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:55)
            org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:64)
            org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:55)
            org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:126)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
            org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
            org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
            org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
            org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
            org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
            org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
            org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
            org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
            org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
            org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
            java.lang.Thread.run(Thread.java:619)
            


            The EntityConverter code is clearly trying to turn my @Id string into an Integer:
             @Transactional
             public Object getAsObject(FacesContext facesContext, UIComponent cmp, String value)
             throws ConverterException
             {
             init();
             if (value == null)
             {
             return null;
             }
             return entityIdentifierStore.get(new Integer(value));
             }
            



            • 3. Re: s:convertEntity with non-numeric @Id
              Pete Muir Master

              No its not, look at the output of getAsString() - we only write an index to the output HTML page - is it easy for you to attach a test case to JIRA?

              Can you post your facelet, source of the list, value for the selection and any related entities just for me to have a complete picture. Thanks!