Warning with ComboBox and JPAContainer



Hello guys,

I have a ComboBox binded to a JPAContainer.

The JPAContainer represents an entity of my DataBase called Brand (eg. Nike, Adidas, etc.)

In my databse I have around 500 different brands stored.

I have a very simple view in my App where a user can search for products in the database and one of the filtering aids I provide the user is selecting the brand from the already mentioned ComboBox.

This works fine, but everytime the user selects a brand (eg. Nike) from the ComboBox I get the following warning:


WARNING: (JPAContainer) WARNING! Invoking indexOfId() when size > 100 is not recommended!

I explicitly don’t call the method indexOfId(), I guess internally the ComboBox calls this due to the fact that it is binded to the JPAContainer!

I have seen the JPAContainer implementation and it says we should never use that method of the JPAContainer, because it is an “ugly” implementation! The source code has the folloing comment:


This is intentionally an ugly implementation! This method should not be used!

I guess I just can’t do anything about it, or can I?

It is just annoying that I get this warning all the time and I just feels it will break or something will go wrong.

If it was me who explicitly called the method I will just try to fix it, but it is called by the ComboBox I guess.

Any opinions, suggestions, fixes, will be received.

Thanx for your help guys!

In
ComboBox.java
there are those lines:

            if (isScrollToSelectedItem() && !optionRequest && selection != null) {
                // ensure proper page
                indexToEnsureInView = indexed.indexOfId(selection);
            }

And then:

/** * Sets whether to scroll the selected item visible (directly open the page * on which it is) when opening the combo box popup or not. Only applies to * single select mode. * * This requires finding the index of the item, which can be expensive in * many large lazy loading containers. * * @param scrollToSelectedItem * true to find the page with the selected item when opening the * selection popup */ public void setScrollToSelectedItem(boolean scrollToSelectedItem) { this.scrollToSelectedItem = scrollToSelectedItem; } As the JavaDoc says, you should disable scroll to select.

Hello Michael,

Thank you for your help, I did not spot that when I came accross the problem. Now this has been fixed!

Thanks again for your reply

Had the same problem with combobox and JPAContainer and I did

comboBox.setScrollToSelectedItem(false) It worked and removed the warning but it introduced another problem. Calling

comboBox.setValue(myValue) The comboBox will only show the value if myValue is in the initial page. If it is outside that it won’t show it :frowning: