0

services are null in spring controller with ZK

asked 2012-06-12 17:11:53 +0800

kossel gravatar image kossel
12

I'm trying to integrate zk with spring, but for somehow I can't make spring instances those service/manage objects :S

Controller, ProductTypecontroller:

 @Controller
    public class ProductTypeController extends SelectorComposer {

        @Resource
        private ProductTypeService productTypeService;

        @Listen("onCreate = listbox#typeList")
        public void loadAll() {
            BindingListModelList model = new BindingListModelList(productTypeService.getAll(), false);
            typeList.setItemRenderer(new ProductTypeListRenderer());
            typeList.setModel(model);   
        }

       public void loadAll2(Listbox lb){
         List lista = productTypeService.getAll();
        BindingListModelList model = new BindingListModelList(lista, false);
        lb.setItemRenderer(new ProductTypeListRenderer());
        lb.setModel(model);              
    }

    }

the Zul
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<zk>
    <hlayout>
    <div id="winDiv" apply="com.iknition.micutecake.controller.ProductTypeController">
        <vbox>
            <listbox id="typeList" width="450px" height="300px" >
                <listhead>
                    <listheader width="50px" label="id" sort="auto(id)" />
                    <listheader width="250px" label="name" sort="auto(name)" />
                    <listheader width="140px" label="description" sort="auto(description)" />
                </listhead>
            </listbox>
        </vbox>
    </div>
        </hlayout>
</zk>

I get NullPointerException because productTypeSerivce is null.

however, if I add

onCreate="loadAll2(self);" 
to the listbox line in .zul then it will call the method
 loadAll2(Listbox lb)
in that way, productTypeService is not null, and everything works fine.

any idea why? or how to make it work?

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2012-07-24 01:46:05 +0800

paowang gravatar image paowang
140 6

check this: http://www.zkoss.org/product/zkspring

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-06-12 17:11:53 +0800

Seen: 149 times

Last updated: Jul 24 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More