To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.
Correct UI components management & Spring framework
1 decade ago Aug 06, 2012 2:03pm
I have doubts about my components management. On the one hand I would go with Spring. Each component is a spring bean, UI initialization happens in @PostConstruct. Beautifull. But then we're stuck with the following problem:
View V has a controller (listener) C that has a DAO D. So it seems like our dependency scope goes like this: V -> C -> D only that we have a problem, controller has to hold reference on view to update it's state correctly after new data was received from the DAO. Circular dependency? We should start passing constructor arguments to listener (that is bad, because we can not use annotation driven injection) or use setters (that is bad also, why would I create an object that has no meaning without a parameter, that is not supplied in the constructor).
So we say "OK, we won't use dependency injection on view side, let the Application bean be ApplicationContextAware and we'll get appropriate daos from it". But now we should build our UI in the attach() method because getApplication() returns null on detached components. And attach is called as many times as there are parrents to that UI component, turning the debugging into hell.
upd: beg my pardon, I have called super.atach() on each form/layout, now it works fine. Anyway, it's interesting what people think about which strategy is better.