replaceComponent() unsupported in Vaadin 7?

Hi All,

I’m finally getting around to looking at Vaadin 7 and there is one oddity that I can’t figure out at this point. I’m hoping that someone would set me straight on this one. In the UI class the replaceComponent method is unsupported for Vaadin 7 (currently looking at beta 3):


UI.class:590:


@Override
public void replaceComponent(Component oldComponent, Component newComponent) {
    throw new UnsupportedOperationException();
}

I know the UI class is new for Vaadin 7 but the replaceComponent method has been around for a long time and was working fine in Vaadin 6 so there is a lot of code out there that is using it. This method seems to be critical for the functionality of single page applications so I was a little surprised to see that it is not supported.

My question is, has there been a replacement for this functionality in the UI class that I am missing or has there been a decision to either delay or eliminate this functionality from Vaadin going forward? Any suggestions would be appreciated. I am currently trying to migrate an application forward from 6 to 7 and this is the last item that is delaying the work.

Thanks.

Gary

I cannot say I know why the replaceComponent() has been removed but I think this may be in relation to the Navigator being added.

Vaadin 7 now includes an easy to use component which is the Navigator. It is basicly the same as replacing a component with other components but with the addition of URI Fragments. You can find more info
here
and
here
.

If your a Spring user I can strongly advise you to look at the Spring implementation of a ViewProvider by Alexander Fedorov
here
.

I appreciate the suggestions but I don’t think Navigator or Spring would be the right options for me in this case. I’m not trying to navigate between views, I’m trying to replace a component and where this is existing code I don’t want to redesign the application if I can avoid it.

I checked the source for v7 beta4 and nothing has changed with replaceComponent() since beta 3. If there was an intent to phase this out wouldn’t it be likely that the stub would be functional and marked deprecated for a few releases, or simply be removed, rather than throw an UnsupportedOperationException?

Any other ideas?

I just checked out the source code for beta4 and the implementation of replaceComponent (com.vaadin.ui.AbstractOrderedLayout#replaceComponent) is still there for most Layout’s (Didn’t check them all). In case you want to switch components on your main UI class you can use com.vaadin.ui.UI#getContent to get the Layout and then use replaceComponent.

Yes, that worked. I was looking for that method in the wrong place. Thanks!

This may be an oversight. I don’t see any reason that UI.replaceComponent() should not just call getContent().replaceComponent().

Fixed in beta 5 (ticket
#9967
).