2 Replies Latest reply on Sep 20, 2008 10:29 AM by nbelaevski

    Problem using data attribute with calendar on same page.

    shadowcreeper

      I think I found a bug with the data attribute in a form with a calendar widget (when the calendar uses a custom data model and comes after the button with the data attribute).

      Following are 2 pages, one works, the other does not (and the backing bean behind them).

      Could somebody else please test this out and confirm?

      I'm using RF 3.2.2.GA, JBoss 4.0.5, MyFaces 1.2.3 and latest Facelets.

      Thanks.
      -Shadow

      Broken page:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE html
       PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      
      <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
       xmlns:rich="http://richfaces.ajax4jsf.org/rich"
       xmlns:ui="http://java.sun.com/jsf/facelets">
      
      <head>
       <a4j:loadScript src="resource://prototype.js"/>
      
       <script type="text/javascript">
       function handleData( myData )
       {
       alert( 'myData: ' + myData );
       if( myData.testValue )
       alert( 'Test Value: ' + myData.testValue );
       else
       alert( 'No Test Value' );
       }
       </script>
      </head>
      
      <body id="mainBody">
      
       <a4j:form>
       <a4j:region>
       <h:panelGrid columns="3">
       <a4j:commandButton styleClass="textButton"
       value="Test"
       data="#{TestBean.testData}"
       oncomplete="handleData( data );"/>
       <rich:calendar popup="false"
       dataModel="#{TestBean.calendarDataModel}"/>
       </h:panelGrid>
       </a4j:region>
       </a4j:form>
      
      </body>
      </html>
      


      Working page:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE html
       PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      
      <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
       xmlns:rich="http://richfaces.ajax4jsf.org/rich"
       xmlns:ui="http://java.sun.com/jsf/facelets">
      
      <head>
       <a4j:loadScript src="resource://prototype.js"/>
      
       <script type="text/javascript">
       function handleData( myData )
       {
       alert( 'myData: ' + myData );
       if( myData.testValue )
       alert( 'Test Value: ' + myData.testValue );
       else
       alert( 'No Test Value' );
       }
       </script>
      </head>
      
      <body id="mainBody">
      
       <a4j:form>
       <a4j:region>
       <h:panelGrid columns="3">
       <rich:calendar popup="false"
       dataModel="#{TestBean.calendarDataModel}"/>
       <a4j:commandButton styleClass="textButton"
       value="Test"
       data="#{TestBean.testData}"
       oncomplete="handleData( data );"/>
       </h:panelGrid>
       </a4j:region>
       </a4j:form>
      
      </body>
      </html>
      


      The only difference is the order of button and calendar widgets.

      Bean code:
      package crc.modes.web.managedbeans;
      
      import org.richfaces.model.CalendarDataModel;
      import org.richfaces.model.CalendarDataModelItem;
      
      import java.io.Serializable;
      import java.util.Date;
      import java.util.Calendar;
      
      public class TestBean
      {
      
       public TestBean ()
       {
       }
      
       public CalendarDataModel getCalendarDataModel ()
       {
       return new TestCalendarDataModel();
       }
      
       public TestData getTestData ()
       {
       final TestData testData = new TestData();
       testData.testValue = "I am a broken test.";
       return testData;
       }
      
       public class TestData
       implements Serializable
       {
       private String testValue;
      
       public String getTestValue ()
       {
       return testValue;
       }
      
       public void setTestValue ( final String testValue )
       {
       this.testValue = testValue;
       }
       }
      
       public class TestCalendarDataModel
       implements CalendarDataModel
       {
       public CalendarDataModelItem[] getData ( final Date[] dates )
       {
       final CalendarDataModelItem[] dataModelItems = new CalendarDataModelItem[dates.length];
       for( int i = 0; i < dates.length; ++i )
       dataModelItems = new TestCalendarDataModelItem( dates );
       return dataModelItems;
       }
      
       public Object getToolTip ( final Date date )
       {
       return null;
       }
       }
      
       public class TestCalendarDataModelItem
       implements CalendarDataModelItem
       {
       private final Date m_date;
      
       public TestCalendarDataModelItem ( final Date date )
       {
       m_date = date;
       }
      
       public boolean isEnabled ()
       {
       return true;
       }
      
       public String getStyleClass ()
       {
       return null;
       }
      
       public Object getData ()
       {
       return null;
       }
      
       public boolean hasToolTip ()
       {
       return false;
       }
      
       public Object getToolTip ()
       {
       return null;
       }
      
       public int getDay ()
       {
       final Calendar calendar = Calendar.getInstance();
       calendar.setTime( m_date );
       return calendar.get( Calendar.DAY_OF_MONTH );
       }
       }
      
      }