Changing standard behaviour of filter component


Is it possible to access properties or methods of subcomponents contained in the standard cuba filter component?
E.g. I have the following request: when a user changes the show-rows dropdown (from 50 to 100 rows let’s assume) the table should refresh instantly, avoiding to press search button.
I tried to debug and I managed to view the components, eventually I saw the weblookupfield with the dropdown. But I failed when trying to access the subcomponent in the code. I hoped I could add a ValueChangedListener to it…
Any solution, if it’s not too complicated?


I think I found it, it wasn’t easy :). On the init method of my screen:

        // filter1 is my filter component
        CubaCssActionsLayout cubaCssActionsLayout = (CubaCssActionsLayout) WebComponentsHelper.unwrap(filter1);
        CubaGroupBox cubaGroupBox = (CubaGroupBox)cubaCssActionsLayout.getComponent(0);
        CubaVerticalActionsLayout cubaVerticalActionsLayout = (CubaVerticalActionsLayout)cubaGroupBox.getContent();
        CubaVerticalActionsLayout cubaVerticalActionsLayout1 =(CubaVerticalActionsLayout)cubaVerticalActionsLayout.getComponent(0);
        CubaHorizontalActionsLayout cubaHorizontalActionsLayout = (CubaHorizontalActionsLayout)cubaVerticalActionsLayout1.getComponent(1);
        CubaHorizontalActionsLayout cubaHorizontalActionsLayout1 = (CubaHorizontalActionsLayout)cubaHorizontalActionsLayout.getComponent(4);
        Component comp = cubaHorizontalActionsLayout1.getComponent(1);

      comp.addListener(new Component.Listener() {
          public void componentEvent(Component.Event event) {
              if (event.getClass().getName() == "com.vaadin.ui.Field$ValueChangeEvent" && event.getSource().getClass().getName() == "com.haulmont.cuba.web.gui.components.WebLookupField$2") {

It works.

You solution may stop working if we do any minor modification in filter component internal structure. Your task can be solved in a different way. There is a demo project attached - take a look.

  1. Override the MaxResultsFieldHelper bean. The new version will set an explicit id to the required combo box.

public class ExtMaxResultsFieldHelper extends MaxResultsFieldHelper {
    public LookupField createMaxResultsLookupField() {
        LookupField maxResultsLookupField = super.createMaxResultsLookupField();
        CubaComboBox cubaComboBox = (CubaComboBox) WebComponentsHelper.unwrap(maxResultsLookupField);
        return maxResultsLookupField;
  1. Register the new bean in the web-spring.xml

<bean id="cuba_MaxResultsFieldHelper" class=""/>
  1. In the screen controller find the comboBox with required id

public class BookBrowse extends AbstractLookup {
    private Filter filter;

    private GroupDatasource<Book, UUID> booksDs;

    public void ready() {
        HasComponents composition = (HasComponents) WebComponentsHelper.getComposition(filter);
        CubaComboBox maxResultsComboBox = WebComponentsHelper.getComponents(composition, CubaComboBox.class)
                .filter(cubaComboBox -> "maxResultsLookupField".equals(cubaComboBox.getId()))

        if (maxResultsComboBox != null) {
            maxResultsComboBox.addValueChangeListener(event -> {
} (34.4K)


It’s working with a minor update:


we have to write: