TwinColSelect Disabled By Default

Dears,

kindly, using TwinColSelect created in a DefaultFieldFactory with the values of its property set in the Model Class.
the TwinColSelect is represented successfully with the values … but the problem is the Its disabled and read-only

i try to set Read-only to True and Enabled to True, but with out success the TwinColSelect is still disabled.

Best Regards,
Shenouda Bertel

Dears,

the Model Class have a method to set the value of this property.

  private List<Integer> colRatesIds(String ratesIds) {
    List<Integer> selection = new ArrayList<Integer>();
    if (ratesIds == null || ratesIds.equalsIgnoreCase("")) {
        return selection;
    } else {
        String[] ratesSID = ratesIds.toString().replace("[", "").replace("]

“, “”).replace(” “, “”).split(”,");
Integer rates_sid = new Integer[ratesSID.length]
;
for (int i = 0; i < ratesSID.length; i++) {
rates_sid[i]
= Integer.parseInt(ratesSID[i]
);
selection.add(rates_sid[i]
);
}
return selection;
}
}

We tried Set, List, Collection, … and all result to the TwinColSelect have selected value but all the component “TwinColSelect” is disabled.

any ideas to solve this issue … as we are pending on.

Best Regards,
Shenouda Bertel

The readOnly setting should be false and enabled true, but those are the defaults so you should not need to change them.

Maybe only setters which do not return a value are considered (JavaBeans specification) - try removing the return value, or renaming the method if you need it elsewhere and then having a setter that calls the renamed method but doesn’t return a value.

Dear Henri,

The Model has setters and getters and the field represented by TwinColSelect is "ratesIds" as follow :

private List ratesIds;

public List getRatesIds() {
return this.ratesIds;
}

public void setRatesIds(String ratesIds) {
    this.ratesIds = colRatesIds(ratesIds);
}

private List<Integer> colRatesIds(String ratesIds) {
    List<Integer> selection = new ArrayList<Integer>();
    if (ratesIds == null || ratesIds.equalsIgnoreCase("")) {
        return selection;
    } else {
        String[] ratesSID = ratesIds.toString().replace("[", "").replace("]

“, “”).replace(” “, “”).split(”,");
Integer rates_sid = new Integer[ratesSID.length]
;
for (int i = 0; i < ratesSID.length; i++) {
rates_sid[i]
= Integer.parseInt(ratesSID[i]
);
selection.add(rates_sid[i]
);
}
return selection;
}
}

That setter & getter for ratesIds return values, the value of rates_ids in database is represented as string "[1, 2, 3]
". which is converted to List
and if i convert “List ratesIds” to “String ratesIds” the TwinColSelect will be enabled and nothing represented as selected.

Please, your help is highly appreciated.

Best Regards,
Shenouda Bertel

Make the get/set use a HashSet instead of a List. I believe that’s what it needs.

Dear David,

kindly, i changed the List to HashSet & also Set to the above code, but nothing changed … the selection in the Right column is done right … but the component is still disabled.

any other things to try as its a weird case.

Thanks,
Shenouda Bertel

Dears,

also kindly find the below attached code for the component creation in FormFieldFactory :

else if (“ratesIds”.equals(propertyId)) {
List rates = ratesHelper.getRates();

        TwinColSelect ratesField = new TwinColSelect();
        ratesField.setRows(rates.size());
        ratesField.setImmediate(true);
        ratesField.setMultiSelect(true);
        ratesField.setNullSelectionAllowed(true);
        ratesField.setLeftColumnCaption("Available Rates");
        ratesField.setRightColumnCaption("Selected Rates");

        for (int i = 0; i < rates.size(); i++) {
            Rates rate = rates.get(i);
            ratesField.addItem(rate.getId());
            ratesField.setItemCaption(rate.getId(), rate.getName());
        }
        return ratesField;
    }

Hope that helps.

Dears,

kindly, find the below from the Testing :

ratesField.getValue()  Type: Collections$UnmodifiableSet
item.getItemProperty("ratesIds").getValue() Type: HashSet

Is the problem for making the component ReadOnly is that the Collection is Unmodifiable Set ?

Thanks,
Shenouda Bertel

Well, assuming the values come from your bean, the idea is that the getter/setter methods take either a Set or HashSet in the interface:

public Set getRates()
public void setRates(Set)

I would use an actual HashSet for getRates() based on your List, something like: return new HashSet(ratesList);

For the setRates, just copy the elements from the Set provided to rebuild your List.

Dear David,

kindly, provide more details for the suggestion & how its implementation differ.

Dears,

By debugging this issue in the Vaadin 6.8.5 & in in the AbstractField Method

and inside bindPropertyToField in the method setPropertyDataSource which take Property (newDataSource) its Type Hashset "property.getValue()"

and after this "dataSource = newDataSource;" the TwinColSelect Readonly changed from false to true.

Why is the value of readOnly changed to True ? and what caused it to be changed to True ?

Please, your help is highly appreciated.

Best Regards,
Shenouda Bertel

Dears,

also, itemDatasource.getItemProperty(“ratesId”) which return the Property … the Property Readonly value property.isRealOnly() is True.

The TwinColSelect becomes read-only because the property is read-only.

The property is probably read-only because it does not find a suitable setter (something wrong with the declaration of the setter - non-matching data types, a return value or something else).

Use a breakpoint in the constructor of the property (and perhaps back-tracking further from there) and wherever its read-only status is changed to find out what makes it read-only.