VwpFAQDropdownDatetime

Converter/Dropdown: How do I get dropdown to recognize my DateTime converter?

I am having problem with the Datetime converter. I added a dropdown list and bound it to a Database table with a field containing Date. I then dropped a Datetime converter on the dropdown list and changed the pattern of the Datetime converter to 'MMMM, yyyy', but the dropdown does not seem to change the date format, it is still showing the default format.


This is a bug. A workaround to this issue is below:

1. Drag & drop the database table to dropdown component.
2. Edit the java for your page containing the dropdown.
3 . Create a property called dateOptions of type java.util.List

          /**
           * Holds value of property dateOptions.
           */
          private java.util.List dateOptions;

          /**
           * Getter for property dateOptions.
           * @return Value of property dateOptions.
           */
          public java.util.List getDateOptions() {

              return this.dateOptions;
          }

          /**
           * Setter for property dateOptions.
           * @param dateOptions New value of property dateOptions.
           */
          public void setDateOptions(java.util.List dateOptions) {

              this.dateOptions = dateOptions;
          }


4. Add the following source to your pre-render method. This will reset the label to the converted string:

          dateOptions = (List)getValue( "#{Page1.tripDataProvider.options[TRIP.DEPDATE,TRIP.DEPDATE]}" );
              for( Iterator iter = dateOptions.iterator(); iter.hasNext(); ) {
                  Option op = (Option)iter.next();
                  Object value = op.getValue();
                  String label = dropDown1Converter.getAsString( FacesContext.getCurrentInstance(), dropDown1, value );
                  op.setLabel( label );
              }
Note: you can cut past the expression
"#{Page1.tripDataProvider.options[TRIP.DEPDATE,TRIP.DEPDATE]}"
from the JSP source code



5. Fix the imports

  • If your application is based on Java EE 5, choose com.sun.webui.jsf.model.Option.
  • If your application is based on J2EE 1.4, choose com.sun.rave.web.ui.model.Option.
  6. Right click on the dropdown component and select Property Bindings. Bind the dropdown items property to the Page1 > dateOptions

The display at designtime will show abc but at runtime it will give the correct result.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo