Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ComboBoxItem allowEmptyValue With a PickList

    Are empty values supported for a ComboBoxItem with a pick list? Here's my class:

    Code:
    public final class MaterialAttrComboBoxItem extends ComboBoxItem {
    
        public MaterialAttrComboBoxItem(final long priceBookId, final long materialAttrTypeId) {
            setAddUnknownValues(false);
            setAllowEmptyValue(true);
    
            // DS values based on price book being positive or negative
            if (priceBookId > 0) {
                setOptionDataSource(DSConst.MaterialAttrSQL.DATASOURCE);
                setSortField(DSConst.MaterialAttrSQL.PRINT_CODE);
                final Criteria criteria = new Criteria();
                criteria.addCriteria(DSConst.MaterialAttrSQL.PRICE_BOOK_ID, priceBookId);
                criteria.addCriteria(DSConst.MaterialAttrSQL.MATERIAL_ATTR_TYPE_ID, materialAttrTypeId);
                setOptionCriteria(criteria);
                setPickListFields(new ListGridField(DSConst.MaterialAttrSQL.PRINT_CODE), new ListGridField(DSConst.MaterialAttrSQL.PRINT_DESCRIPTION));
                setValueField(DSConst.MaterialAttrSQL.PRINT_CODE);
                setDisplayField(DSConst.MaterialAttrSQL.PRINT_CODE);
            } else {
                setOptionDataSource(DSConst.MaterialAttrPBDBSQL.DATASOURCE);
                setSortField(DSConst.MaterialAttrPBDBSQL.PRINT_CODE);
                final Criteria criteria = new Criteria();
                criteria.addCriteria(DSConst.MaterialAttrPBDBSQL.PRICE_BOOK_ID, -priceBookId);
                criteria.addCriteria(DSConst.MaterialAttrPBDBSQL.MATERIAL_ATTR_TYPE_ID, materialAttrTypeId);
                setOptionCriteria(criteria);
                setPickListFields(new ListGridField(DSConst.MaterialAttrPBDBSQL.PRINT_CODE), new ListGridField(DSConst.MaterialAttrPBDBSQL.PRINT_DESCRIPTION));
                setValueField(DSConst.MaterialAttrPBDBSQL.PRINT_CODE);
                setDisplayField(DSConst.MaterialAttrPBDBSQL.PRINT_CODE);
            }
    
            final ListGrid pickListProps = new ListGrid();
            pickListProps.setAlternateRecordStyles(true);
            pickListProps.setAutoFitData(Autofit.HORIZONTAL);
            pickListProps.setAutoFitFieldWidths(true);
            pickListProps.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
            setPickListProperties(pickListProps);
        }
    
    }
    I don't get any empty values in the list, I'm assuming this isn't supported with using a pick list.

    For another workaround, I was looking at setting specialValues: https://www.smartclient.com/smartgwt...java.util.Map-

    The documentation mentions a special constant "emptyStoredValue". How would I use that?

    Thanks!

    #2
    Yes, empty values are supported in numerous ways. The questions are:

    1. what you want to happen when the empty value is chosen: just clear the text entry area, show something special, or what?

    2. what do you want getValue() to return, and what should be stored? In other words, do you have an empty value that is distinct from just the user entering nothing?

    See allowEmptyValue, see emptyDisplayValue for what is displayed when the field is empty.

    emptyStoredValue is a constant used when defining specialValues, to indicate that picking that specialValue sets the field to empty. In other words it is the key in the Map for a specialValue that should set the field value to null when picked.

    Comment


      #3
      1. I just want the field to be set to null. This is a dropdown from a ListGrid. The value in the ListGrid field can be set back to null.

      2. Null is fine for getValue()

      My problem is there isn't a "blank" value in the dropdown to click on.

      Comment


        #4
        OK, then if you do not want to return a special record representing blank from your DataSource, specialValues is the right approach, using emptyStoredValue as previously indicated.

        Comment


          #5
          Perfect, that's working now!

          Comment

          Working...
          X