TwinColSelect Selection

Dears,

kindly, i faced a problem with using TwinColSelect, as the values i select from after retrieved back not represented in the selected column as follow :

        TwinColSelect ratesField = new TwinColSelect();
        ratesField.setRows(rates.size());
        ratesField.setNullSelectionAllowed(true);
        ratesField.setMultiSelect(true);
        ratesField.setImmediate(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());
        }

        if (item.getItemProperty("id").getValue() != null) {
            // As the value retrieved from database is "[1,2,3]

"
String account_id = item.getItemProperty(“id”).toString();
Accounts modif_account = accountHelper.getAccount(Integer.parseInt(account_id));
String ratesSID = modif_account.getRatesIds().replace(“[”, “”).replace(“]
“, “”).replace(” “, “”).split(”,”);
ratesField.setValue(Arrays.asList(ratesSID));
}

      and nothing represented in the Right Column "Selected Column"
      also, when i try ratesField.select() after addItem nothing represented in the Right Column "Selected Column"

Please, help
Shenouda Bertel

I’m not sure if you could use
List
for TwinColSelect#SetValue().

Try using a
HashSet
?
[url=http://demo.vaadin.com/book-examples/book/?restartApplication#component.select.twincolselect.basic]

http://demo.vaadin.com/book-examples/book/?restartApplication#component.select.twincolselect.basic
[/url]

Dear Kevin,

kindly, i try your comment as follow :

HashSet<String> preselected = new HashSet<String>();
Collections.addAll(preselected, ratesSID);
 ratesField.setValue(preselected);

with the same result nothing represented in the Right Column "Selected Column".

Best Regards,
Shenouda Bertel

Shenouda,

Have you debugged to make sure that the objects’ you are using for
TwinColSelect#addItem(Object itemId)
are the same objects that you are using in the HashSet to set the values to?

Dear Kevin,

kindly, as per your below update … i have checked the code as following :

String ratesSID = modif_account.getRatesIds().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 ]
);
}
HashSet preselected = new HashSet();
Collections.addAll(preselected, rates_sid);
ratesField.setValue(preselected);

As the TwinColSelect#addItem(Object itemId) is rate.getId() which is Integer

and also, nothing changes … nothing represented in the selected column.

As for experiment is try to TwinColSelect#select(rate.getId()) after TwinColSelect#addItem(rate.getId()) with the same result “Selecting column empty”

Best Regards,
Shenouda Bertel

Dears,

kindly, find the below code regarding TwinColSelect case in DefaultFieldFactory

        List<Rates> rates = ratesHelper.getRates();
        TwinColSelect ratesField = new TwinColSelect();
        ratesField.setRows(rates.size());
        ratesField.setNullSelectionAllowed(true);
        ratesField.setMultiSelect(true);
        ratesField.setImmediate(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());
        }

        if (item.getItemProperty("id").getValue() != null) {
            // item.getItemProperty("ratesIds") as "[1, 2, 3]

"
String ratesSID = item.getItemProperty(“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]
);
}
HashSet preselected = new HashSet();
Collections.addAll(preselected, rates_sid);
ratesField.setValue(preselected);
}
return ratesField;

The TwinColSelect is not representing the Selected Values in the Right Column.

Looking for you support regarding this issue.

Thanks,
Shenouda Bertel