I am using ZK to try to call Spring Manager/DAO from the existing spring JAR project. I already use this variable resolver in the zul file:
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<zk>
<window border="normal" width="400px" style="padding-top:20px;padding-left:20px;" title="Species Editor" apply="org.openforis.specieseditor.NewSpecies">
And able to call in the Java class NewSpecies.java this way :
SpeciesManager speciesManager = (SpeciesManager) SpringUtil.getBean("speciesManager");
List<TaxonOccurrence> speciesList = speciesManager.findByScientificName(taxonomy, species, 1);
The problem is, inside this SpeciesManager.java there is a call to other DAO, e.g taxonDao, which create a Null Pointer Exception. And I really clueless of how this exception occur. Any help? I already add this taxonDao inside my spring config xml also.
You have
apply="org.openforis.specieseditor.NewSpecies"on your root component which means ZK will instantiate your composer instance and then Spring has no chance to inject the dependency as composer is not a Spring managed bean here. You can inject Spring dependencies in your composer by extending from SelectorComposer and VariableResolver annotation as shown belowOR
You can make your current
NewSpeciesinto a Spring managed bean and use EL expression likeapply="${newSpecies}"to let Spring handle the lifecycle of NewSpecies bean (Note: make sure NewSpecies has prototype scope)