Exception: Trying to push a detached ui

Hi all! I am new in Vaadin. So I writed my demo application and during it execution time to time I received “com.vaadin.ui.UIDetachedException: Trying to push a detached ui” exception, when trying to push updates from server.
Could you explain me what it means and why it happens?

Hi Maryna,

I had the same problem using Vaadin 7.2.6. Did you get any further insight into it?

For me the problem doesn’t occur all the time.

-Rohan

Hello Maryna & Rohan

Can you please share your snippet of code? So that I help debugging the issue.

Technicallly speaking, it means the UI is already detached from the current session and the New Updates are being pushed. Check if the session is getting invalidated, user Inactivity and also on how updates are being pushed.

Thanks,
Krishna.

Hey Krishna,

I have a UI object with a custom component inside it. The custom component is given a callback to the UI’s push method:
This is scala code, but I’m not using scaladin - just straight Vaadin 7.2.6 code. Here’s a simplification of what I’m doing:

[code]
@Push
class MyUI extends UI {
override def init(…) {
val myComponent = new MyComponent(() => this.push())

setContent(myComponent)

}

}

class MyComponent(uiCallback: Unit=>Unit) extends CustomComponent {

// This component represents a table.
// When a new element gets added it calls the uiCallback passed in at construction.
}
[/code]Many different servlets are adding new rows to the component which is then calling the push method back on the main UI.

Thanks for any help and let me know if you need more info.

-Rohan

Hello Rohan,

This piece of code is fine. In order to resolve the issue at hand, I want you to debug hence add a detach listener/ method in your UI class. And once you identify that your UI is detached(you will know via Detached listener) checkout from which servlet your UI refresh/poll is getting called, which causes UI detached exception. Take corrective actions at this point either doing a check if the UI is currently available/attached, if attached push the changes else ignore the changes.

Sadly, As access to the code is limited, I can just give you pointers to resolve your issue :frowning:

Thanks,
Krishna.

I resolved my issue. The problem was following:
I have aplication, which make requests to different services and show results of requests on web. So I have couple of threads which are doing this and for each update I used UI.getCurrent().push(). It seems that in different threads UI was invisible or something like that. And instead this I added setPollInterval(60000) in init() method in main UI and it make calls to server. If something changed it refresh my page.

Thanks for the feedback. The problem hasn’t happened for me for a while so I can’t really debug it.

I’ll add more info here if it happens again.