2 Replies Latest reply on Jul 29, 2011 10:57 AM by laszlovandenhoek

    rich calender for jbpm task variable not working

    peterbasutkar

      Hi All

                i am using jbpm 3.2.6 and rich faces 3.3.1 in my application i have requirement where i wanted to modify task variable(date field) in jsf and i am using rich calender for that taskVariable in my page like following

       

      <rich:calendar value="#{taskVariableMap['startDate']}" popup="true" datePattern="d/M/yy HH:mm" />

       

      where taskVariableMap is Map which contains variables(context variables) from jbpm database

       

      but when i try to call any action in this jsf page.it is giving following exception

       

      16:45:23,520 ERROR [STDERR] Feb 21, 2011 4:45:23 PM javax.faces.component.UIInput updateModel

      java.lang.IllegalArgumentException: Cannot convert 12/12/12 12:00 AM of type class java.util.Date to class java.sql.Timestamp

       

      i try using converter also for Date to Timestamp conversion but still gives same exception.

       

      if i remove this rich calender component then i am not getting any exception and i am able call all the actions in this form

        • 1. Re: rich calender for jbpm task variable not working
          laszlovandenhoek

          I'm using the jBPM 3.2.10 packaged with JBoss SOA Platform 5.1, but on all other points you are describing exactly the same problem I'm having.

           

          The problem does not occur the first time you enter a value in the rich:calendar (that is, you are not overwriting any previously registered process variables). Therefore, I suspect the problem is that jBPM persists this initial Date through the underlying DbPersistenceService, and then the next time you retrieve the value from the database, it is wrapped in a java.sql.Timestamp and rich:calendar trips over it.

           

          This gives rise to two possible solutions: either make the DbPersistenceService return a java.util.Date, or make rich:calendar properly handle java.sql.Timestamp values.

          • 2. Re: rich calender for jbpm task variable not working
            laszlovandenhoek

            I solved the problem using a Converter. I used this Ilya Shaikovsky's example in this thread as a starting point:http://community.jboss.org/message/57921

             

            in faces-config.xml:

             

            {code:xml}

            <converter>

              <converter-id>calendarTimestampConverter</converter-id>

              <converter-class>my.client.CalendarTimestampConverter</converter-class>

            </converter>

            {code:xml}

             

            CalendarTimestampConverter.java:

             

             

            {code:java}

            package my.client;

             

             

            import java.util.Date;

             

             

            import javax.faces.component.UIComponent;

            import javax.faces.context.FacesContext;

            import javax.faces.convert.ConverterException;

            import javax.faces.convert.DateTimeConverter;

             

             

            import org.apache.log4j.Logger;

             

             

            public class CalendarTimestampConverter extends DateTimeConverter {

             

                      private Logger logger = Logger.getLogger(getClass());

             

                      @Override

                      public Object getAsObject(FacesContext arg0, UIComponent component, String dateString) {

                                logger.debug("getAsObject(): " + dateString);

                                Object result;

                                try {

                                          result = super.getAsObject(arg0, component, dateString);

                                          if (result instanceof Date) {

                                                    //make it a Timestamp, because that is what jBPM will make of it anyway

                                                    result = new java.sql.Timestamp(((Date) result).getTime());

                                          }

                                } catch (ConverterException ex) {

                                          return null;

                                }

                                return result;

                      }

             

             

                      @Override

                      public String getAsString(FacesContext arg0, UIComponent component, Object dateObject) {

                                logger.debug("getAsString(): " + (dateObject == null ? null : (dateObject.getClass().getSimpleName() + " " + dateObject.toString())));

                                String result = null;

                                try {

                                          result = super.getAsString(arg0, component, dateObject);

                                } catch (ConverterException ex) {

                                          return null;

                                }

                                return result;

                      }

            }

            {code:java}

             

            Then I simply add converter="calendarTimestampConverter" to my rich:calendar, and presto! No more jBPM problems.

             

            Still, this is a hack and should be fixed in jBPM, IMO.