Revision history [back]

click to hide/show revision 1
initial version

asked 2013-07-15 08:37:41 +0800

demizon gravatar image demizon

spring + zk @autowired

Hi, I m trying to implement zk to existing spring app.

This is example of class from spring, which i want to use in zk modelview:

@Service
@Transactional
public class JobOrderControllerImpl{

     //@Resource(name="jobOrderDao")
     @Autowired
     JobOrderDao jobOrderDao;

     @Autowired
     HarnessbaseDao harnessbaseDao;

     @Autowired
     HarnesstypeDao harnesstypeDao;

public Harnesstype findHarnesstype(int id){
                DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Harnesstype.class);
                           detachedCriteria.add(Restrictions.eq("id", id));
        return harnesstypeDao.getHarnesstype(detachedCriteria);
            }
}

in spring I am using it like this:

@Controller
@RequestMapping("/getData")
public class JobOrderGetData {
    //private ApplicationContext context;
    private Logger log = Logger.getLogger(JobOrderGetData.class);

    @Autowired    
    JobOrderControllerImpl jobOrderControler;
 @RequestMapping(value = "getHarnessType")
    @ResponseBody
    public Harnesstype getHarnessType( @RequestParam("id") int id) {
        Harnesstype ht = jobOrderControler.findHarnesstype(id);    
        return ht;
    }
}

but when i try to use it in my zk modelview like this:

public class GeneratorViewModel {   
   @Autowired
    private JobOrderControllerImpl jobOrderController;
@Command   
    public void getCount() {
        harnesstype = jobOrderController.findHarnesstype(2);        
        }}

I am getting following error:

SEVERE: java.lang.NullPointerException at com.leoni.emo.general.modelViews.GeneratorViewModel.getCount(GeneratorViewModel.java:113) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.zkoss.bind.impl.ParamCall.call(ParamCall.java:111) at org.zkoss.bind.impl.BinderImpl.doExecute(BinderImpl.java:1736) at org.zkoss.bind.impl.BinderImpl.doCommand(BinderImpl.java:1497) at org.zkoss.bind.impl.BinderImpl.access$1500(BinderImpl.java:106) at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent0(BinderImpl.java:1373) at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent(BinderImpl.java:1325) at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2742) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2713) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2654) at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136) at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1717) at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1502) at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1212) at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:600) at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:482) at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:491) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907) at java.lang.Thread.run(Thread.java:619) 15.7.2013 9:32:15 org.zkoss.bind.impl.BinderImpl$CommandEventListener onEvent:1327

I guess I am doing something wrong with autowired variable... Thank you for your help.

spring + zk @autowired@autowired problem

Hi, I m trying to implement zk to existing spring app.

This is example of class from spring, which i want to use in zk modelview:

@Service
@Transactional
public class JobOrderControllerImpl{

     //@Resource(name="jobOrderDao")
     @Autowired
     JobOrderDao jobOrderDao;

     @Autowired
     HarnessbaseDao harnessbaseDao;

     @Autowired
     HarnesstypeDao harnesstypeDao;

public Harnesstype findHarnesstype(int id){
                DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Harnesstype.class);
                           detachedCriteria.add(Restrictions.eq("id", id));
        return harnesstypeDao.getHarnesstype(detachedCriteria);
            }
}

in spring I am using it like this:

@Controller
@RequestMapping("/getData")
public class JobOrderGetData {
    //private ApplicationContext context;
    private Logger log = Logger.getLogger(JobOrderGetData.class);

    @Autowired    
    JobOrderControllerImpl jobOrderControler;
 @RequestMapping(value = "getHarnessType")
    @ResponseBody
    public Harnesstype getHarnessType( @RequestParam("id") int id) {
        Harnesstype ht = jobOrderControler.findHarnesstype(id);    
        return ht;
    }
}

but when i try to use it in my zk modelview like this:

public class GeneratorViewModel {   
   @Autowired
    private JobOrderControllerImpl jobOrderController;
@Command   
    public void getCount() {
        harnesstype = jobOrderController.findHarnesstype(2);        
        }}

I am getting following error:

SEVERE: java.lang.NullPointerException at com.leoni.emo.general.modelViews.GeneratorViewModel.getCount(GeneratorViewModel.java:113) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.zkoss.bind.impl.ParamCall.call(ParamCall.java:111) at org.zkoss.bind.impl.BinderImpl.doExecute(BinderImpl.java:1736) at org.zkoss.bind.impl.BinderImpl.doCommand(BinderImpl.java:1497) at org.zkoss.bind.impl.BinderImpl.access$1500(BinderImpl.java:106) at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent0(BinderImpl.java:1373) at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent(BinderImpl.java:1325) at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2742) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2713) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2654) at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136) at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1717) at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1502) at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1212) at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:600) at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:482) at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:491) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907) at java.lang.Thread.run(Thread.java:619) 15.7.2013 9:32:15 org.zkoss.bind.impl.BinderImpl$CommandEventListener onEvent:1327

I guess I am doing something wrong with autowired variable... Thank you for your help.

spring + zk @autowired problem

Hi, I m trying to implement zk to existing spring app.

This is example of class from spring, which i want to use in zk modelview:

@Service
@Transactional
public class JobOrderControllerImpl{

     //@Resource(name="jobOrderDao")
     @Autowired
     JobOrderDao jobOrderDao;

     @Autowired
     HarnessbaseDao harnessbaseDao;

     @Autowired
     HarnesstypeDao harnesstypeDao;

public Harnesstype findHarnesstype(int id){
                DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Harnesstype.class);
                           detachedCriteria.add(Restrictions.eq("id", id));
        return harnesstypeDao.getHarnesstype(detachedCriteria);
            }
}

in spring I am using it like this:

@Controller
@RequestMapping("/getData")
public class JobOrderGetData {
    //private ApplicationContext context;
    private Logger log = Logger.getLogger(JobOrderGetData.class);

    @Autowired    
    JobOrderControllerImpl jobOrderControler;
 @RequestMapping(value = "getHarnessType")
    @ResponseBody
    public Harnesstype getHarnessType( @RequestParam("id") int id) {
        Harnesstype ht = jobOrderControler.findHarnesstype(id);    
        return ht;
    }
}

but when i try to use it in my zk modelview like this:

public class GeneratorViewModel {   
   @Autowired
    private JobOrderControllerImpl jobOrderController;
@Command   
    public void getCount() {
        harnesstype = jobOrderController.findHarnesstype(2);        
        }}

I am getting following error:

SEVERE: java.lang.NullPointerException at com.leoni.emo.general.modelViews.GeneratorViewModel.getCount(GeneratorViewModel.java:113) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.zkoss.bind.impl.ParamCall.call(ParamCall.java:111) at org.zkoss.bind.impl.BinderImpl.doExecute(BinderImpl.java:1736) at org.zkoss.bind.impl.BinderImpl.doCommand(BinderImpl.java:1497) at org.zkoss.bind.impl.BinderImpl.access$1500(BinderImpl.java:106) at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent0(BinderImpl.java:1373) at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent(BinderImpl.java:1325) at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2742) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2713) at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2654) at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136) at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1717) at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1502) at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1212) at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:600) at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:482) at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:491) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907) at java.lang.Thread.run(Thread.java:619) 15.7.2013 9:32:15 org.zkoss.bind.impl.BinderImpl$CommandEventListener onEvent:1327

I guess I am doing something wrong with autowired variable... Thank you for your help.

my zul file:

<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>

<groupbox title="Tlac etikiet" closable="false" apply="org.zkoss.bind.BindComposer"
          viewModel="@id('vm') @init('com.leoni.emo.general.modelViews.GeneratorViewModel')">

    <grid width="700px">
        <rows>

            <row>
                Zadajte typ kablovky:
                <textbox value="@bind(vm.harnesstypeAliasName)" onOK="@command('getCount')"/>
            </row>

            <row visible="@load(vm.showStep2)">
                <label value="Pocet kabloviek" width="150px"/>
                <hlayout>
                    <combobox width="150px" visible="@load(vm.showStep2)" model="@load(vm.numberList)"
                              selectedItem="@bind(vm.selectedNumber)" readonly="true" onOK="@command('generateUniqueJobOrder')">
                        <template name="model">
                            <comboitem label="@load(each)"/>
                        </template>

                    </combobox>
                </hlayout>

            </row>
        </rows>

    </grid>

    <button mold="trendy" visible="@load(vm.showStep1)" label="OK" onClick="@command('getCount')"/>
    <button mold="trendy" visible="@load(vm.showStep2)" label="GenerovaƄ sprievodku"
            onClick="@command('generateUniqueJobOrder')"/>
    <separator bar="true"/>


    <listbox height="590px" model="@load(vm.jobOrderList)" emptyMessage="No joborders">
        <auxhead>
            <auxheader colspan="4" class="topic">Joborder List</auxheader>
        </auxhead>
        <listhead>
            <listheader width="95%" align="center" label="Job order ID"/>
            <listheader width="95%" align="center" label="Order number"/>
            <listheader width="95%" align="center" label="Status"/>
            <listheader width="95%" align="center" label="Created date"/>
            <listheader width="95%" align="center" label="Number of harnesses"/>
            <listheader width="95%" align="center" label="Print"/>
        </listhead>
        <template name="model">
            <listitem>
                <!--listcell label="@load(each.id)"/-->
                <listcell label="@load(each.harnesstypeid)"/>
                <listcell label="@load(each.ordernumber)"/>
                <listcell label="@load(each.status)"/>
                <listcell label="@load(each.numberofharnesses)"/>
                <listcell label="@load(each.createddate)"/>
                <listcell>
                    <button label="Print" mold="trendy" onClick="@command('printJobOrder', jobOrder=each)"/>

                </listcell>
            </listitem>
        </template>
    </listbox>


</groupbox>
Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More