GridLayout removeComponent doesn't work

I have a View which extends GridLayout and has a 2x2 - Matrix.

Now I want to programmatically remove a component in one of the cells of the GridLayout with:


this.removeComponent( component );

But the component doesn’t get removed at least the browser view doesn’t get updated.

I also used:

this.removeComponent( col , row , component );

But the problem is still the same.

UPDATE: When I first do a component count :


int c = this.getComponentCount();

I get four.

After the removeComponent I get THREE - so it get’s removed but the browser doesn’t reflect this.

Any ideas what the problem could be?

Thanks in advance,

Frank

Hi Frank,

Could you post your source code?

I tried a simple example and it works fine:

    @Override
    protected void init(VaadinRequest request) {

        final GridLayout layout = new GridLayout(3, 1);
        setContent(layout);

        final Label labelA = new Label("A");
        final Label labelB = new Label("B");
        final Button button = new Button("Remove A", new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                layout.removeComponent(labelA);
            }
        });

        layout.addComponents(button, labelA, labelB);
    }

Hi,

I guess the it has to do with the fact that I don’t use this Vaadin-Push-Framework.



com.vaadin
vaadin-push

and then use the @Push - Annotation on the UI.

I will post my source code later - right now I don’t have it here.

Do you use UI.access() when making changes from the background thread?

Hi,

I do not make changes from another thread. I just call removeComponent on one of my views and the component I want to remove is in a GridLayout.

All I want to do is in my View which is part of the MainUI:

removeComponent( col , row );

I want to remove a view from a certain cell in a GridLayout and it doesn’t work.
I enabled push and I can see that the atmosphere framework is configured and it seems to work. But the component isn’t removed - actually it seems that it is removed on the server but the client is not updated.

Best Regards,

Frank

Ok, then I don’t see how push is related. Source code?

This is the source code of the view with the GridLayout:

[font=courier new]
@Theme(value = “mytheme”)
@Widgetset( value = “info.frankmarx.MyAppWidgetset” )
@SpringView( name = “” )
@Scope( value = “prototype” )
@Log4j2
public class MainView extends VerticalLayout implements View , ViewInstanceAccessControl {

public final static String VIEW_NAME = "main";
protected final GridLayout layout = new GridLayout( 2 , 2 );

@Autowired
IOtherService otherService;

@Autowired
MainMenuView mainMenuView;

@Autowired
LogoView logoView;

@Autowired
MGView mgView;

@Autowired
ShopFloorView shopFloorView;

@Autowired
MachineListView machineListView;

@PostConstruct
protected void initView() {
    log.info("| Entering initView().");
    layout.setSizeFull();
    layout.setWidth(100, Unit.PERCENTAGE);
    layout.setHeight(100, Unit.PERCENTAGE);
    layout.setSpacing(false);

    this.addStyleName("backColorGrey");

    logoView.addStyleName("backColorRed");
    mgView.addStyleName("backColorGreen");
    mainMenuView.addStyleName("backColorGrey");

    layout.addComponent(logoView, 0, 0);
    layout.addComponent(mgView, 0, 1);
    layout.addComponent(mainMenuView, 1, 0);
    layout.addComponent(shopFloorView, 1, 1);

    layout.setColumnExpandRatio(1, 4.0f);
    layout.setSpacing(false);
    //this.setRowExpandRatio( 0 , 1.0f );

    mainMenuView.setSizeFull();

    //this.setStyleName("backColorBlue");
    float er = layout.getColumnExpandRatio(1);
    layout.setColumnExpandRatio(0, 1.0f);
    layout.setColumnExpandRatio(1, 10);
    layout.setComponentAlignment(mainMenuView, Alignment.TOP_LEFT);
    layout.setRowExpandRatio(1, 0.5f);

    mainMenuView.setWidth(100, Unit.PERCENTAGE);
    this.addComponent( layout );
    log.info("| Exiting initView().");
}

@Override
public void enter(ViewChangeListener.ViewChangeEvent viewChangeEvent) {
    log.info("| Entering enter with event {}.", viewChangeEvent.toString());

    log.info("| Exiting enter.");
}

@Override
public boolean isAccessGranted(UI ui, String s, View view) {
    log.info("| isAccessGranted was called with {} , {}" , s , view.toString() );
    return true;
}

public boolean setComponentForGrid( int column, int row, String viewName ) {

    if( viewName.equalsIgnoreCase( MACHINE_LIST_VIEW )) {
        int c = this.getComponentCount();
        layout.removeComponent( 1 , 1 );
        int x  = 0;
    }
    return true;
}

}
[/font]

The method “setComponentForForGrid” is called from a Click-Handler and is supposed to remove a component from the GridLayout - but the client doesn’t get updated.

Best Regards,

Frank

Hmmm … somehow it seems to work now.

I have no idea what went wrong - let’s hope it stays this way.

Thank you!

cheers,

Frank