Modify UI "before request ends"

Hello community,

I’d like to implement a
ComponentStatePolicy
with Vaadin 7.1. The main requirement is to enable/disable components based on the application state (i.e. UI component state, access rights, business rules (order value > 100.000€), …).

My design idea is as follows:
Every Component may have a
ComponentStatePolicy

public interface ComponentStatePolicy {
    boolean isEnabled();
}

The
ComponentStatePolicy
(if a component has one) is kept in
AbstractComponent#applicationData
. There are alternatives like keeping them in the
View
or in the
Presenter
but this does not matter for the problem I am currently facing.

Every time a request has been processed, the UI component tree is traversed to enabled/disable all components having a
ComponentStatePolicy
associated.
Traversal starts at
UI.getCurrent().getContent()
and walks through the component hierarchy calling

ComponentData applicationData = (...)component.getData();
component.setEnabled(applicationData.getComponentStatePolicy().isEnabled()) 

for each visible component.

Now the tricky part: I would like to have a
generic
solution to assert that every request causes the previously described evaluation of all applicable
ComponentStatePolicies
.
So: Where is the best place to intercept the request processing to traverse the component hierarchy in order to enable/disable the components every time a request is about to be returned to the client?

To clarify the requirement: I do
not
want to implement a listener for every little thing which might cause a component state to change. That would result in a gazillon listeners and it would be practically impossible to make sure every
ComponentStatePolicy
is evaluated exactly once.

I already tried to do it in an overridden
UI.beforeClientResponse(boolean)
, but no luck (seems to be to late in the request processing). I was also looking for appropriate
*Listener
to use or for methods in
VaadinServlet
/
VaadinService
which may help. But no luck so far.

Any ideas would be very appreciated,
Sascha

Hi Sascha,
I’m facing a similar problem.
UI.beforeClientResponse(boolean) works for me if I use push mechanism but I would rather like to not do so.

Have you found a proper solution?