|
From: <jue...@we...> - 2003-11-12 10:02:38
|
Darren,
I don't know if you've noticed that I've added a related feature =
yesterday: AbstractView has now not only the standard =
setAttributes(Properties) and setAttributesCSV(String) but also =
setAttributesMap(Map). The latter allows not only for String values but =
also for refs, lists, maps, and props as static model attributes.
To make refs work, I've reworked XmlViewResolver and =
ResourceBundleViewResolver to create their view bean factories as =
children of the surrounding application context. Else, you would not be =
able to reference beans in the application context from view =
definitions.
To not put beans themselves as static attributes into the model but =
rather other objects, maybe use a FactoryBean that returns the model =
attribute? The name of the attribute would be determined by the map key =
in the view definition then. It might still make sense to support a =
special ModelReference bean that creates a whole map of attribute =
key/value pairs.
And BTW, <ref external=3D"..."/> is somewhat deprecated as there is no =
strict check for just referencing external beans. <ref bean=3D"..."/> is =
now the generic one that can reference any bean in any reachable =
context, while <ref local=3D"..."/> can just reference local beans in =
the same XML file (via XML ids).
Juergen
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...]On Behalf
Of Darren Davison
Sent: Wednesday, November 12, 2003 2:50 AM
To: spr...@li...
Subject: [[W3-SPAM]] - Re: [Springframework-developer] About MVC - Email
found in subject
On Tuesday 11 November 2003 23:27, Darren Davison wrote:
> Is there something already in Spring MVC that lends itself to this =
kind
> of behaviour?
without really thinking this through much (since it's gone 1:30am and I =
have=20
to be up again in 4 hours)..
If an interface..
public interface ModelReference {
public Map getModel();
}
.. is implemented by some arbitrary business objects, then a view could =
be=20
defined as..
<bean id=3D"myVelocityView"
class=3D"org.springframework.web.servlet.view.velocity.VelocityView">
<property name=3D"templateName"><value>main.vm</value></property> =20
<!-- standard attribs -->
<property name=3D"attributes">
<props>
<prop key=3D"title">A Velocity Page</prop>
</props>
</property> =20
<!-- new property: list of ModelReference implementing bus. objects =
-->
<property name=3D"references">
<list>
<ref external=3D"myBean"/>
<ref external=3D"myOtherBean"/>
</list>
</property> =20
</bean>
AbstractView is amended with the following (part pseudo-code)..
public abstract class AbstractView extends WebApplicationObjectSupport=20
implements View {
//added
private Map referenceObjects =3D new HashMap();
...
//added
public final void setReferencesList(List references) { =20
for each list item
get bean from app context if exists
if bean instanceof ModelReference=20
call bean.getModel()=20
consolidate into referenceObjects field
end
end
}
//amended
public final void render(Map model, HttpServletRequest request,=20
HttpServletResponse response)
=20
...
Map mergedModel =3D new HashMap(this.staticAttributes);
mergedModel.putAll(referenceObjects);
mergedModel.putAll(model);
...
}
}
- The controller still has final say and can overwrite model values =
from=20
the static list or the reference list
- Arbitrary beans can now add to the model that a view renders on a per =
view basis taking advantage of whatever container resources or custom =
logic=20
is required
- multiple views can use the same ref objects via the hierarchical view =
structure
- It's a kind of half-way house between static attributes and model =
data=20
returned by the controller but as shown isn't parameterised so =
reasonably=20
rigid
- maybe the interface can be dropped and the actual method to call for =
any=20
given bean can be specified in the config too. One less dependency for =
the=20
business object
Goodnight.
--=20
Darren Davison
Public Key: http://www.davison.uk.net/key.jsp
-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|