-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I am a newbie on Zk. I have written two zul pages for study ZK. But I got two problems.
First, I have two ZUL pages. One is working fine, but another page is not working. All button on click event can not fire.
Error page:
<?xml version="1.0" encoding="UTF-8"?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <zk> <window title="Base Basket Maintenance" border="normal" apply="${baseBasketMaintViewCtrl}"> <listbox> <listhead> <listheader align="left" width="150px" /> <listheader align="left" /> </listhead> <listitem> <listcell label="Basket Id:" /> <listcell> <textbox id="txtbox_basketId" /> </listcell> </listitem> <listitem> <listcell label="Base Basket Description:"/> <listcell> <textbox id="txtbox_baseBasketDesc"/> </listcell> </listitem> <listitem> <listcell label="MCO CD:" /> <listcell> <textbox id="txtbox_mcoCD" /> </listcell> </listitem> <listitem> <listcell label="RP CD:" /> <listcell> <textbox id="txtbox_rpCD" /> </listcell> </listitem> <listitem> <listcell label="Bundle CD:" /> <listcell> <textbox id="txtbox_bundleCD" /> </listcell> </listitem> <listitem> <listcell/> <listcell> <button id="btnSearchBaseBasket" label="Search" /> <space /> <button id="btnClearBaseBasketSearch" label="Clear" /> </listcell> </listitem> </listbox> <separator/> <style> .z-label { display:block; } tr.z-row td.z-row-inner { padding: 2px 5px; } .z-row-cnt, .z-column-cnt { text-align: center; } </style> <grid id="offerGrid" model="${model}" emptyMessage="Empty" sizedByContent="true" span="true"> <auxhead> <auxheader label="Base Baseket Information" colspan="8" /> </auxhead> <columns> <column label="BASKET_ID"/> <column label="DESCRIPTION"/> <column label="RP_CD"/> <column label="BUNDLE_CD"/> <column label="MCO_CD"/> <column label="RP_DESC"/> <column label="BUNDLE_DESC"/> <column label="MCO_DESC"/> </columns> </grid> </window> </zk>
And its controller:
/** * */ package com.bomwebadminportal.web; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.zkoss.spring.context.annotation.EventHandler; import org.zkoss.spring.util.GenericSpringComposer; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; import org.zkoss.zul.Button; import org.zkoss.zul.Grid; import org.zkoss.zul.ListModelList; import org.zkoss.zul.Textbox; import com.bomwebadminportal.dto.BaseBasketDTO; import com.bomwebadminportal.service.BaseBasketService; /** * @author 01238971 * */ @org.springframework.stereotype.Component("${baseBasketMaintViewCtrl}") @Scope("desktop") public class BaseBasketMaintenanceViewCtrl extends GenericSpringComposer{ protected final Log logger = LogFactory.getLog(getClass()); @Autowired private Grid offerGrid; @Autowired private Button btnClearBaseBasketSearch; @Autowired private Button btnSearchBaseBasket; @Autowired private Textbox txtbox_mcoCD; @Autowired private Textbox txtbox_bundleCD; @Autowired private Textbox txtbox_rpCD; @Autowired private Textbox txtbox_baseBasketDesc; @Autowired private Textbox txtbox_basketId; @Autowired private BaseBasketService baseBasketService; /** * * */ @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); // TODO Auto-generated method stub } @EventHandler("btnClear.onClick") public void clear(Event evt) throws InterruptedException { txtbox_mcoCD.setValue(""); txtbox_bundleCD.setValue(""); txtbox_rpCD.setValue(""); txtbox_baseBasketDesc.setValue(""); txtbox_basketId.setValue(""); } @EventHandler("btnSearch.onClick") public void search(Event evt) throws InterruptedException { List<BaseBasketDTO> baseBasketList = baseBasketService.getBaseBasketSearchDisplay(txtbox_basketId.getText() , txtbox_baseBasketDesc.getText() , txtbox_mcoCD.getText() , txtbox_rpCD.getText() , txtbox_bundleCD.getText()); List model = new ListModelList(baseBasketList); offerGrid.setModel((ListModelList)model); } }
The another problem, I have written a render class to put dynamic data into a grid. I also put two button on each row of the grid for update delete row action. However, both buttons in the row have something wrong. Everytime I click one of the button. It will throw exception. The exception is following:
2011年9月21日 下午05:20:26 org.zkoss.zk.ui.impl.UiEngineImpl handleError:1280 嚴重的: >>java.lang.NullPointerException >> at com.bomwebadminportal.web.ui.BasketMaintenanceDynamicRowRenderer$7.onEvent(BasketMaintenanceDynamicRowRenderer.java:121) >> at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192) >> at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138) >> at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1636) >> at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1420) >> at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1133) >> at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:567) >> at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:462) >> at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:470) >> at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) >> at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) >> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) >> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) >> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) >> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) >> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) >> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) >> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) >> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) >> at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) >> at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) >> at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) >> at java.lang.Thread.run(Unknown Source)
The render class is following:
package com.bomwebadminportal.web.ui; import java.io.Serializable; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; import org.zkoss.zul.Button; import org.zkoss.zul.Datebox; import org.zkoss.zul.ListModelList; import org.zkoss.zul.Row; import org.zkoss.zul.RowRenderer; import org.zkoss.zul.Textbox; import com.bomwebadminportal.dao.DicBasketItemAssignDAO; import com.bomwebadminportal.dto.DicBasketItemAssignDTO; import com.bomwebadminportal.service.DiscBasketItemAssignService; @org.springframework.stereotype.Component("BasketMaintenanceDynamicRowRenderer") @Scope("desktop") public class BasketMaintenanceDynamicRowRenderer implements RowRenderer ,Serializable{ /** * */ private static final long serialVersionUID = -8142328797477003655L; @Autowired private DiscBasketItemAssignService discBasketItemAssignService; public void render(final Row row, final java.lang.Object data) { DicBasketItemAssignDTO dicBasketItemAssignDTO = (DicBasketItemAssignDTO) data; final Textbox txt_basketId = new Textbox(); txt_basketId.setValue(dicBasketItemAssignDTO.getBasketId()); txt_basketId.setInplace(true); txt_basketId.addEventListener(Events.ON_CHANGE, new org.zkoss.zk.ui.event.EventListener() { public void onEvent(Event event) { txt_basketId.setStyle("font-weight:bold"); } }); row.appendChild(txt_basketId); final Textbox txt_itemId = new Textbox(); txt_itemId.setValue(dicBasketItemAssignDTO.getItemId()); txt_itemId.setInplace(true); txt_itemId.addEventListener(Events.ON_CHANGE, new org.zkoss.zk.ui.event.EventListener() { public void onEvent(Event event) { txt_itemId.setStyle("font-weight:bold"); } }); row.appendChild(txt_itemId); final Textbox txt_mdoInd = new Textbox(); txt_mdoInd.setValue(dicBasketItemAssignDTO.getMdoInd()); txt_mdoInd.setInplace(true); txt_mdoInd.addEventListener(Events.ON_CHANGE, new org.zkoss.zk.ui.event.EventListener() { public void onEvent(Event event) { txt_mdoInd.setStyle("font-weight:bold"); } }); row.appendChild(txt_mdoInd); final Textbox txt_displaySeq = new Textbox(); txt_displaySeq.setValue(dicBasketItemAssignDTO.getDisplaySeq()); txt_displaySeq.setInplace(true); txt_displaySeq.addEventListener(Events.ON_CHANGE, new org.zkoss.zk.ui.event.EventListener() { public void onEvent(Event event) { txt_displaySeq.setStyle("font-weight:bold"); } }); row.appendChild(txt_displaySeq); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date startDate = new Date(); try { if (!"".equals(dicBasketItemAssignDTO.getEffStartDate())||dicBasketItemAssignDTO.getEffStartDate()!=null) startDate = sdf.parse(dicBasketItemAssignDTO.getEffStartDate()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } final Datebox dt_effStartDate = new Datebox(); dt_effStartDate.setValue(startDate); dt_effStartDate.setFormat("medium"); dt_effStartDate.setInplace(true); dt_effStartDate.addEventListener(Events.ON_CHANGE, new org.zkoss.zk.ui.event.EventListener() { public void onEvent(Event event) { dt_effStartDate.setStyle("font-weight:bold"); } }); row.appendChild(dt_effStartDate); Date endDate = new Date(); try { if (!"".equals(dicBasketItemAssignDTO.getEffEndDate())||dicBasketItemAssignDTO.getEffEndDate()!=null) endDate = sdf.parse(dicBasketItemAssignDTO.getEffEndDate()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } final Datebox dt_effEndDate = new Datebox(); dt_effEndDate.setValue(endDate); dt_effEndDate.setFormat("medium"); dt_effEndDate.setInplace(true); dt_effEndDate.addEventListener(Events.ON_CHANGE, new org.zkoss.zk.ui.event.EventListener() { public void onEvent(Event event) { dt_effEndDate.setStyle("font-weight:bold"); } }); row.appendChild(dt_effEndDate); final Button rm = new Button("Delete"); rm.addEventListener(Events.ON_CLICK, new EventListener() { public void onEvent(Event event) throws Exception { discBasketItemAssignService.deleteDicBasketItemAssign((DicBasketItemAssignDTO) data); ListModelList tmplist = new ListModelList((ListModelList)row.getGrid().getModel()); tmplist.remove(data); row.getGrid().setModel(tmplist); } }); row.appendChild(rm); final Button upd = new Button("Update"); upd.addEventListener(Events.ON_CLICK, new EventListener() { public void onEvent(Event event) throws Exception { discBasketItemAssignService.updateDicBasketItemAssign((DicBasketItemAssignDTO) data); ListModelList tmplist = new ListModelList((ListModelList)row.getGrid().getModel()); row.getGrid().setModel(tmplist); } }); row.appendChild(upd); } }
Hope anyone can give me suggestion to solving them. Thanks so much
Hi Uncle1212,
for the first problem, please check whether it is really 'composed' first,
you may print some message in doAfterCompose by System.out to check it.
For the second problem, maybe the data is cleared in method updateDicBasketItemAssign or somewhere else,
the better way is put data into Event then get it, please refer to the related thread:
zau.send parameter not accessible
and the javadoc
Event
Hi benbai,
Thanks you for answer my questions.
I following your suggestion to testing those problems.
for the first problem, I put system.out in doAfterCompose, no message is printed. I am chasing the problem.
for the second problem, updateDicBasketItemAssign() is a function which I use to update table in database. I use event.getData() to get the data from event. It return null. However, the "data" Object which I put into updateDicBasketItemAssign() is contain the values of the row I want to update. Therefore, I guest the problem is event return null value, and its make this event return null value exception. So Is it means that I need to set value into event and get it out from it again?
Thanks
Yes, you should set data each time you trigger an event, because they are distinct instance.
and if it still null after you set data into event, please refer to the thread about ForwardEvent here
Hi benbai,
Thanks for you answer me again.
I am still working on this problem. I create a simple page to study this case. It is a window contain a listbox, and have some text field let me input data. Then I click insert button to insert data into database, but I still get the problem like past. But I just want to set data into a DTO object........its come out exception again.
I have check the event instance. they are same.
Therefore, I would like to ask, how to set data into event. So that I could use event.getData() to avoid the null pointer exception.......
The following is my page:
<?xml version="1.0" encoding="UTF-8"?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <?page title="Trade Description" contentType="text/html;charset=UTF-8"?> <zk> <window title="Trade Description" border="normal" apply="${tradeDescriptionViewCtrl}"> <listbox> <listhead> <listheader label="" sort="auto" /> <listheader label="" sort="auto" /> </listhead> <listitem> <listcell style="font-size: 12px;" label="Model ID:" /> <listcell> <intbox width="98%" id="intbox_MODEL_ID" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Brand:" /> <listcell> <textbox width="98%" id="txtbox_BRAND" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Model:" /> <listcell> <textbox width="98%" id="txtbox_MODEL" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Place of manufacture:" /> <listcell> <textbox width="98%" id="txtbox_PLACE_OF_MANUFACTURE" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Network frequency or operating frequency or band:" /> <listcell> <textbox width="98%" id="txtbox_NETWORK_FREQ" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Type of support memory card:" /> <listcell> <textbox width="98%" id="txtbox_STORAGE_TYPE" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Maximum capacity of support memory card:" /> <listcell> <textbox width="98%" id="txtbox_STORAGE_CAPACITY" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Data transfer/network connectivity protocol:" /> <listcell> <textbox width="98%" id="txtbox_NETWORK_PROTOCOL" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Resolution of the camera in terms of pixels (where the phone has a built‐in camera):" /> <listcell> <textbox width="98%" id="txtbox_CAMERA_RESOLUTION" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Identity of repair service provider:" /> <listcell> <textbox width="98%" id="txtbox_REPAIR_SRV_PRDR" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Repair service address:" /> <listcell> <textbox width="98%" id="txtbox_REPAIR_SRV_ADDR" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Warranty period - Handset:" /> <listcell> <textbox width="98%" id="txtbox_WARRANTY_PERIOD_HS" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Warranty period - Accessory:" /> <listcell> <textbox width="98%" id="txtbox_WARRANTY_PERIOD_ACC" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Create by:" /> <listcell> <textbox width="98%" id="txtbox_CREATE_BY" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Last update by:" /> <listcell> <textbox width="98%" id="txtbox_LAST_UPD_BY" /> </listcell> </listitem> </listbox> <button style="font-size: 12px;" id="btntradeDescInsert" label="Insert" /> <button style="font-size: 12px;" id="btntradeDescClear" label="Clear" /> </window> </zk>
and the following is my controller:
package com.bomwebadminportal.web; import org.springframework.beans.factory.annotation.Autowired; import org.zkoss.spring.context.annotation.EventHandler; import org.zkoss.spring.util.GenericSpringComposer; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.ForwardEvent; import org.zkoss.zul.Button; import org.zkoss.zul.Intbox; import org.zkoss.zul.Messagebox; import org.zkoss.zul.Textbox; import com.bomwebadminportal.dto.TradeDescriptionDTO; import com.bomwebadminportal.service.TradeDescriptionService; /** * @author 01256692 * */ @org.springframework.stereotype.Component("tradeDescriptionViewCtrl") public class TradeDescriptionViewCtrl extends GenericSpringComposer { @Autowired private Button btntradeDescClear; @Autowired private Button btntradeDescInsert; @Autowired private Textbox txtbox_LAST_UPD_BY; @Autowired private Textbox txtbox_CREATE_BY; @Autowired private Textbox txtbox_WARRANTY_PERIOD_ACC; @Autowired private Textbox txtbox_WARRANTY_PERIOD_HS; @Autowired private Textbox txtbox_REPAIR_SRV_ADDR; @Autowired private Textbox txtbox_REPAIR_SRV_PRDR; @Autowired private Textbox txtbox_CAMERA_RESOLUTION; @Autowired private Textbox txtbox_NETWORK_PROTOCOL; @Autowired private Textbox txtbox_STORAGE_CAPACITY; @Autowired private Textbox txtbox_STORAGE_TYPE; @Autowired private Textbox txtbox_NETWORK_FREQ; @Autowired private Textbox txtbox_PLACE_OF_MANUFACTURE; @Autowired private Textbox txtbox_MODEL; @Autowired private Textbox txtbox_BRAND; @Autowired private Intbox intbox_MODEL_ID; private TradeDescriptionService tradeDescriptionService; public TradeDescriptionService getTradeDescriptionService() { return tradeDescriptionService; } public void setTradeDescriptionService( TradeDescriptionService tradeDescriptionService) { this.tradeDescriptionService = tradeDescriptionService; } /** * * */ @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); // TODO Auto-generated method stub } @EventHandler("btntradeDescInsert.onClick") public void Insert(Event evt) throws InterruptedException { if ("".equals(intbox_MODEL_ID.getValue())){ Messagebox.show("Please input Model ID.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_BRAND.getValue())){ Messagebox.show("Please input Brand.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_MODEL.getValue())){ Messagebox.show("Please input Model.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_PLACE_OF_MANUFACTURE.getValue())){ Messagebox.show("Please input Place of manufacture.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_NETWORK_FREQ.getValue())){ Messagebox.show("Please input Network frequency or operating frequency or band.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_STORAGE_TYPE.getValue())){ Messagebox.show("Please input Type of support memory card.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_STORAGE_CAPACITY.getValue())){ Messagebox.show("Please input Maximum capacity of support memory card.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_NETWORK_PROTOCOL.getValue())){ Messagebox.show("Please input Data transfer/network connectivity protocol.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_CAMERA_RESOLUTION.getValue())){ Messagebox.show("Please input Resolution of the camera in terms of pixels (where the phone has a built‐in camera).","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_REPAIR_SRV_PRDR.getValue())){ Messagebox.show("Please input Identity of repair service provider.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_REPAIR_SRV_ADDR.getValue())){ Messagebox.show("Please input Repair service address.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_WARRANTY_PERIOD_HS.getValue())){ Messagebox.show("Please input Warranty period - Handset.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_WARRANTY_PERIOD_ACC.getValue())){ Messagebox.show("Please input Warranty period - Accessory.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_CREATE_BY.getValue())){ Messagebox.show("Please input Create by.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_LAST_UPD_BY.getValue())){ Messagebox.show("Please input Last update by.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; } System.out.println("evt :" + evt); System.out.println(evt.getData()); TradeDescriptionDTO dto = new TradeDescriptionDTO(); Event orgin; if(evt instanceof ForwardEvent){ System.out.println("same instance"); orgin = Events.getRealOrigin((ForwardEvent)evt); } else{ System.out.println("not same instance"); orgin = evt; } dto.setModelID(intbox_MODEL_ID.getText()); dto.setBrand(txtbox_BRAND.getText()); dto.setModel(txtbox_MODEL.getText()); dto.setPlaceOfManufacture(txtbox_PLACE_OF_MANUFACTURE.getText()); dto.setNetworkFreq(txtbox_NETWORK_FREQ.getText()); dto.setStorageType(txtbox_STORAGE_TYPE.getText()); dto.setStorageCapacity(txtbox_STORAGE_CAPACITY.getText()); dto.setNetworkProtocol(txtbox_NETWORK_PROTOCOL.getText()); dto.setCameraResolution(txtbox_CAMERA_RESOLUTION.getText()); dto.setRepairSrvPrdr(txtbox_REPAIR_SRV_PRDR.getText()); dto.setRepairSrvAddr(txtbox_REPAIR_SRV_ADDR.getText()); dto.setWarrantyPeriodHS(txtbox_WARRANTY_PERIOD_HS.getText()); dto.setWarrantyPeriodAcc(txtbox_WARRANTY_PERIOD_ACC.getText()); dto.setCreateBy(txtbox_CREATE_BY.getText()); dto.setLastUpdBy(txtbox_LAST_UPD_BY.getText()); tradeDescriptionService.insertTradeDescription(dto); } }
the following is error message:
Error message: Sep 23, 2011 5:22:39 PM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1280 SEVERE: >>java.lang.NullPointerException >> at com.bomwebadminportal.web.TradeDescriptionViewCtrl.Insert(TradeDescriptionViewCtrl.java:171) >> 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.spring.util.GenericSpringComposer.onEvent(GenericSpringComposer.java:217) >> at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192) >> at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138) >> at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:306) >> at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:329) >> at org.zkoss.zk.ui.AbstractComponent$ForwardListener.onEvent(AbstractComponent.java:3034) >> at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192) >> at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138) >> at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1636) >> at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1420) >> at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1133) >> at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:567) >> at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:462) >> at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:470) >> at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) >> at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) >> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) >> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) >> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) >> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) >> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) >> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) >> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) >> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) >> at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) >> at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) >> at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) >> at java.lang.Thread.run(Thread.java:662)
Hi benbai,
Thanks for you answer me again.
I am still working on this problem. I create a simple page to study this case. It is a window contain a listbox, and have some text field let me input data. Then I click insert button to insert data into database, but I still get the problem like past. But I just want to set data into a DTO object........its come out exception again.
I have check the event instance. they are same.
Therefore, I would like to ask, how to set data into event. So that I could use event.getData() to avoid the null pointer exception.......
The following is my page:
<?xml version="1.0" encoding="UTF-8"?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <?page title="Trade Description" contentType="text/html;charset=UTF-8"?> <zk> <window title="Trade Description" border="normal" apply="${tradeDescriptionViewCtrl}"> <listbox> <listhead> <listheader label="" sort="auto" /> <listheader label="" sort="auto" /> </listhead> <listitem> <listcell style="font-size: 12px;" label="Model ID:" /> <listcell> <intbox width="98%" id="intbox_MODEL_ID" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Brand:" /> <listcell> <textbox width="98%" id="txtbox_BRAND" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Model:" /> <listcell> <textbox width="98%" id="txtbox_MODEL" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Place of manufacture:" /> <listcell> <textbox width="98%" id="txtbox_PLACE_OF_MANUFACTURE" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Network frequency or operating frequency or band:" /> <listcell> <textbox width="98%" id="txtbox_NETWORK_FREQ" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Type of support memory card:" /> <listcell> <textbox width="98%" id="txtbox_STORAGE_TYPE" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Maximum capacity of support memory card:" /> <listcell> <textbox width="98%" id="txtbox_STORAGE_CAPACITY" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Data transfer/network connectivity protocol:" /> <listcell> <textbox width="98%" id="txtbox_NETWORK_PROTOCOL" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Resolution of the camera in terms of pixels (where the phone has a built‐in camera):" /> <listcell> <textbox width="98%" id="txtbox_CAMERA_RESOLUTION" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Identity of repair service provider:" /> <listcell> <textbox width="98%" id="txtbox_REPAIR_SRV_PRDR" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Repair service address:" /> <listcell> <textbox width="98%" id="txtbox_REPAIR_SRV_ADDR" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Warranty period - Handset:" /> <listcell> <textbox width="98%" id="txtbox_WARRANTY_PERIOD_HS" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Warranty period - Accessory:" /> <listcell> <textbox width="98%" id="txtbox_WARRANTY_PERIOD_ACC" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Create by:" /> <listcell> <textbox width="98%" id="txtbox_CREATE_BY" /> </listcell> </listitem> <listitem> <listcell style="font-size: 12px;" label="Last update by:" /> <listcell> <textbox width="98%" id="txtbox_LAST_UPD_BY" /> </listcell> </listitem> </listbox> <button style="font-size: 12px;" id="btntradeDescInsert" label="Insert" /> <button style="font-size: 12px;" id="btntradeDescClear" label="Clear" /> </window> </zk>
and the following is my controller:
package com.bomwebadminportal.web; import org.springframework.beans.factory.annotation.Autowired; import org.zkoss.spring.context.annotation.EventHandler; import org.zkoss.spring.util.GenericSpringComposer; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.ForwardEvent; import org.zkoss.zul.Button; import org.zkoss.zul.Intbox; import org.zkoss.zul.Messagebox; import org.zkoss.zul.Textbox; import com.bomwebadminportal.dto.TradeDescriptionDTO; import com.bomwebadminportal.service.TradeDescriptionService; /** * @author 01256692 * */ @org.springframework.stereotype.Component("tradeDescriptionViewCtrl") public class TradeDescriptionViewCtrl extends GenericSpringComposer { @Autowired private Button btntradeDescClear; @Autowired private Button btntradeDescInsert; @Autowired private Textbox txtbox_LAST_UPD_BY; @Autowired private Textbox txtbox_CREATE_BY; @Autowired private Textbox txtbox_WARRANTY_PERIOD_ACC; @Autowired private Textbox txtbox_WARRANTY_PERIOD_HS; @Autowired private Textbox txtbox_REPAIR_SRV_ADDR; @Autowired private Textbox txtbox_REPAIR_SRV_PRDR; @Autowired private Textbox txtbox_CAMERA_RESOLUTION; @Autowired private Textbox txtbox_NETWORK_PROTOCOL; @Autowired private Textbox txtbox_STORAGE_CAPACITY; @Autowired private Textbox txtbox_STORAGE_TYPE; @Autowired private Textbox txtbox_NETWORK_FREQ; @Autowired private Textbox txtbox_PLACE_OF_MANUFACTURE; @Autowired private Textbox txtbox_MODEL; @Autowired private Textbox txtbox_BRAND; @Autowired private Intbox intbox_MODEL_ID; private TradeDescriptionService tradeDescriptionService; public TradeDescriptionService getTradeDescriptionService() { return tradeDescriptionService; } public void setTradeDescriptionService( TradeDescriptionService tradeDescriptionService) { this.tradeDescriptionService = tradeDescriptionService; } /** * * */ @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); // TODO Auto-generated method stub } @EventHandler("btntradeDescInsert.onClick") public void Insert(Event evt) throws InterruptedException { if ("".equals(intbox_MODEL_ID.getValue())){ Messagebox.show("Please input Model ID.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_BRAND.getValue())){ Messagebox.show("Please input Brand.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_MODEL.getValue())){ Messagebox.show("Please input Model.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_PLACE_OF_MANUFACTURE.getValue())){ Messagebox.show("Please input Place of manufacture.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_NETWORK_FREQ.getValue())){ Messagebox.show("Please input Network frequency or operating frequency or band.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_STORAGE_TYPE.getValue())){ Messagebox.show("Please input Type of support memory card.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_STORAGE_CAPACITY.getValue())){ Messagebox.show("Please input Maximum capacity of support memory card.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_NETWORK_PROTOCOL.getValue())){ Messagebox.show("Please input Data transfer/network connectivity protocol.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_CAMERA_RESOLUTION.getValue())){ Messagebox.show("Please input Resolution of the camera in terms of pixels (where the phone has a built‐in camera).","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_REPAIR_SRV_PRDR.getValue())){ Messagebox.show("Please input Identity of repair service provider.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_REPAIR_SRV_ADDR.getValue())){ Messagebox.show("Please input Repair service address.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_WARRANTY_PERIOD_HS.getValue())){ Messagebox.show("Please input Warranty period - Handset.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_WARRANTY_PERIOD_ACC.getValue())){ Messagebox.show("Please input Warranty period - Accessory.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_CREATE_BY.getValue())){ Messagebox.show("Please input Create by.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; }else if ("".equals(txtbox_LAST_UPD_BY.getValue())){ Messagebox.show("Please input Last update by.","Missing value", Messagebox.OK, Messagebox.INFORMATION); return; } System.out.println("evt :" + evt); System.out.println(evt.getData()); TradeDescriptionDTO dto = new TradeDescriptionDTO(); Event orgin; if(evt instanceof ForwardEvent){ System.out.println("same instance"); orgin = Events.getRealOrigin((ForwardEvent)evt); } else{ System.out.println("not same instance"); orgin = evt; } dto.setModelID(intbox_MODEL_ID.getText()); dto.setBrand(txtbox_BRAND.getText()); dto.setModel(txtbox_MODEL.getText()); dto.setPlaceOfManufacture(txtbox_PLACE_OF_MANUFACTURE.getText()); dto.setNetworkFreq(txtbox_NETWORK_FREQ.getText()); dto.setStorageType(txtbox_STORAGE_TYPE.getText()); dto.setStorageCapacity(txtbox_STORAGE_CAPACITY.getText()); dto.setNetworkProtocol(txtbox_NETWORK_PROTOCOL.getText()); dto.setCameraResolution(txtbox_CAMERA_RESOLUTION.getText()); dto.setRepairSrvPrdr(txtbox_REPAIR_SRV_PRDR.getText()); dto.setRepairSrvAddr(txtbox_REPAIR_SRV_ADDR.getText()); dto.setWarrantyPeriodHS(txtbox_WARRANTY_PERIOD_HS.getText()); dto.setWarrantyPeriodAcc(txtbox_WARRANTY_PERIOD_ACC.getText()); dto.setCreateBy(txtbox_CREATE_BY.getText()); dto.setLastUpdBy(txtbox_LAST_UPD_BY.getText()); tradeDescriptionService.insertTradeDescription(dto); } }
the following is error message:
Error message: Sep 23, 2011 5:22:39 PM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1280 SEVERE: >>java.lang.NullPointerException >> at com.bomwebadminportal.web.TradeDescriptionViewCtrl.Insert(TradeDescriptionViewCtrl.java:171) >> 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.spring.util.GenericSpringComposer.onEvent(GenericSpringComposer.java:217) >> at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192) >> at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138) >> at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:306) >> at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:329) >> at org.zkoss.zk.ui.AbstractComponent$ForwardListener.onEvent(AbstractComponent.java:3034) >> at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:192) >> at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138) >> at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1636) >> at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1420) >> at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1133) >> at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:567) >> at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:462) >> at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:470) >> at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) >> at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) >> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) >> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) >> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) >> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) >> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) >> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) >> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) >> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) >> at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) >> at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) >> at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) >> at java.lang.Thread.run(Thread.java:662)
Hi uncle1212,
for forward event with data,
please refer to Event Forwarding and Event Handling as need
Asked: 2011-09-21 05:15:33 +0800
Seen: 457 times
Last updated: Sep 23 '11