4 Replies Latest reply on Jul 21, 2009 12:27 PM by cash1981

    Problem using Seam currentDate

    oyesiji77

      I am trying to use the Seam currentDate Component,



      I am injecting it into my bean using


      @In CurrentDate currentDate;


      but whenever i try accessing the page that uses the backing bean , I always get this exception



      
      Caused by: java.lang.IllegalArgumentException: could not set field value: newListing.currentDate
              at org.jboss.seam.Component.setFieldValue(Component.java:1894)
              at org.jboss.seam.Component.access$600(Component.java:127)
              at org.jboss.seam.Component$BijectedField.set(Component.java:2902)
              at org.jboss.seam.Component.injectAttributes(Component.java:1703)
              at org.jboss.seam.Component.inject(Component.java:1521)
              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
              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.core.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:32)
              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)
      
      Caused by: java.lang.IllegalArgumentException: Could not set field value by reflection: NewListingBean.currentDate on: com.nairakobo.action.NewListingBean with value: class java.sql.Date
              at org.jboss.seam.util.Reflections.set(Reflections.java:86)
              at org.jboss.seam.Component.setFieldValue(Component.java:1890)
              ... 116 more






      Any help would be appreciated

        • 1. Re: Problem using Seam currentDate
          cash1981

          Could you explain why you want to use this component?

          • 2. Re: Problem using Seam currentDate
            zhangxiubo

            It seems to be a type mismatch error.




            @Name("org.jboss.seam.framework.currentDate")
            @Install(precedence=BUILT_IN)
            @Scope(ScopeType.STATELESS)
            @AutoCreate
            public class CurrentDate
            {
               @Unwrap 
               public Date getCurrentDate()
               {
                  return new java.sql.Date( System.currentTimeMillis() );
               }
            }





            It is apparent that the org.jboss.seam.framework.CurrentDate does not extend java.util.Data which is the super class of java.sql.Date. Referencing the CurrentDate only return you the a date object populated with the current date but the component itself should not be assigned with a Date object. Is your currentDate initialised with a Date object elsewhere?

            • 3. Re: Problem using Seam currentDate
              oyesiji77

              I am trying to use this component because I would like to obtain the current Date, although i can also use new Date(), I would have preferred using a Seam component

              • 4. Re: Problem using Seam currentDate
                cash1981

                Jubril Oyesiji wrote on Jul 20, 2009 15:31:


                I am trying to use this component because I would like to obtain the current Date, although i can also use new Date(), I would have preferred using a Seam component


                Remember that this will take much longer time to perform instead of just new Date();
                It will need to do a lookup and locate the currentDate component. Then go through all the interceptors and then perform unwrap. Really unnecessary if you just want a date object.


                Take a look at joda-time if you have bigger date stuff to perform.