-
FEATURED COMPONENTS
First time here? Check out the FAQ!
This is extremely frustrating and I hope there is a work around or else I'll have to go back to doing things the 'non standard away'
I want to inject a properties value into my ViewModel using @Value (or some annotation?) eg:
@Value("${someProp}")
private String someProp;
The issue is this only seems to work when I declare my ViewModel using the anti-pattern:
@Component("myViewModel")
@Scope("prototype")
public class MyViewModel {
and then in my zul...
<window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init(myViewModel)" >
However the zk spring docs recommend NOT declaring your ViewModel as a component, so if I follow the correct pattern, how do I inject a property? @Value doesn't work and @WireVariable does not work either.
Thanks. I really need to get this addressed since we need to inject properties in a lot of our view models.
I came up with a work-around, but it's not nice. We should be able to leverage something similar to @Value... maybe spring-zk with an @WireValue ?
Anyway, my work around ...
1) Declare a util to the props file in your config:
<util:properties id="adminProps" location="classpath:web-application.properties" />
NOTE: previously using @Value all I needed to declare was:
<context:property-placeholder location="classpath:web-application.properties" ignore-resource-not-found="true" ignore-unresolvable="true"/>
2) Directly inject the properties file in your view model with @WiveVariable
@WireVariable
protected Properties adminProps;
3) When you need a property access it from the properties object you injected
String url = adminProps.getProperty("helpUrl");
Asked: 2013-05-08 23:17:33 +0800
Seen: 37 times
Last updated: May 09 '13
ZK Calendar Wire Spring-managed Beans Failed [closed]
Spring security doesn't return user inside event listener
where to put @Transactional (Hibernate Spring)
Clustered Session Terracotta not working
Not able to bind Spring beans after zk upgrade
retriving Spring authentication provider Name dynamically in multiple authentication providers