|
From: Darren D. <dda...@kg...> - 2003-11-25 09:34:24
|
The addition of the setAttributesMap(Map) in AbstractView, and Colin's new
MethodInvokingFactoryBean actually combine quite well to allow an arbitrary
(and possibly unmodifiable) business object to contribute model data to one or
more views in isolation of any controller that provides the main model. Which
is good, because this is something that would be of great use to us here and
which has been mentioned (admittedly mainly by me) on this list a couple of times.
There is a bit of an obstacle to it working the way we need though. Because
the bean is added to the view as a 'static attribute' it only ever gets
evaluated once before the view is cached by the resolver for the first time.
Is there any way we could mark an individual view with a property in
views.(properties|xml) that tells AbstractCachingViewResolver that the
staticAttributes should be re-evaluated (at least if they are of type
FactoryBean)?
It would need AbstractCachingViewResolver to be modified I guess along the
lines of;
private void reloadAttributes(View v) {
/*
1. get static attribute map from view
2. iterate over entries looking for entries of type FactoryBean
3. call addStaticAttribute() if of type FactoryBean (or force a call on
getObject())
*/
}
To prevent a general degradation of view efficiency, this method would be
called conditionally just prior to returning the view object in
AbstractCachingViewResolver.resolveViewName() if the view had been marked as
'dynamic' or whatever..
public final View resolveViewName(String viewName, Locale locale) throws
ServletException {
...
if (viewIsDynamic) reloadAttributes(view);
return view;
}
Any thoughts?
--
Darren Davison
Public Key: http://www.davison.uk.net/key.jsp
|