0

get value doublebox inside listbox

asked 2012-08-06 05:14:40 +0800

onsir gravatar image onsir
132 2

How to get value doublebox inside list box ? because i have try like this result is empty

Process is:
1 i want get data form database and add/store to listbox
2. then i input value money in doublebox
3. then i wan save data from listbox
4. but result for doublebox always empty

i have code like this

UnitPrice.zul

<?xml version="1.0" encoding="UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" root="./winUnitPrice" ?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<zk xmlns="http://www.zkoss.org/2005/zul"
	xmlns:h="http://www.w3.org/1999/xhtml"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">


 <listbox id="listUnitPrice" multiple="true" rows="10"  checkmark="true"  mold="paging" pageSize="20" >                                    
                   <listhead>
	     	    <listheader label="ItemCode"  width="100px" sort="auto(itemCode)"/>
                                <listheader label="Price"     width="150px"/>
                    </listhead>
	 
	            <listitem self="@{each='Item'}" value="@{Item}">
	            <listcell label="@{Item.itemCode}"/>
	            <listcell><doublebox id="dblPrice" constraint="no negative" width="90%" />
                          </listitem>
</listbox>
                        
<div>
     <button id="btnSave" label="Save" forward="onClick=onBtnClickSave(evt)" />
 </div>


UnitPriceController.java

public class UnitPriceController extends GenericForwardComposer {

    @Autowired private ItemService ItemService;
    private Item item;
    
    private Listbox listUnitPrice;
    private ListModelList listModelUnitPrice = new ListModelList();
    
     
    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);
        // TODO Auto-generated method stub
        MessInfoError.doSetTemplate();
    }




//mehod for add row in list box
 public void onBtnClickShowItem(Event evt) {
        try {
                    List<Item> listItem=new ArrayList<Item>();
                    listItem=(List)event.getData();
                    for(Item items : listItem){
                        item=new Item();
                        item.setItemCode(items.getItemCode());
                       
                        listModelUnitPrice.add(item);
                        listUnitPrice.setModel(listModelUnitPrice);
                    }
                 
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }


public void onBtnClickSave(Event evt) {
     try {
            int lineNo=1;
            for (Object item : listUnitPrice.getItems()) {
                listUnitPrice.renderItem((Listitem) item);
                for (Object cell : ((Listitem) item).getChildren()) {
                    if (((Listcell) cell).getListheader() != null) {
                        if (((Listcell) cell).getListheader().getColumnIndex() == 0) {
                            valueIdItem=(((Listcell) cell).getLabel());
                        }

                        if (((Listcell) cell).getListheader().getColumnIndex() == 1) {
                           <b >this result alway empty</b>
                           // this result valuePrice = 
                           System.out.println("valuePrice = " + (((Listcell) cell).getLabel()));
                           
                        }

                    }
               }
           } catch (Exception e) {
              e.printStackTrace();
           }
    }




thanks

delete flag offensive retag edit

8 Replies

Sort by ยป oldest newest

answered 2012-08-06 06:28:38 +0800

MontyPan gravatar image MontyPan
435 3
http://xitop.blogspot.com...

Hi onsir,

I can't find the code you fetch value from doublebox?
Because "doublebox" is not a label of listcell,

(((Listcell) cell).getLabel()));

will get nothing.

Regards,
Monty Pan

link publish delete flag offensive edit

answered 2012-08-06 06:44:34 +0800

onsir gravatar image onsir
132 2

i don't know code for fetch doublebox,
have any sample ?

link publish delete flag offensive edit

answered 2012-08-06 06:57:08 +0800

MontyPan gravatar image MontyPan
435 3
http://xitop.blogspot.com...

An intuition but ugly way:

((Doublebox)(cell.getChildren().get(0))).getValue()

In my opinion, i will use ZK MVVM....

Regards,
Monty Pan

link publish delete flag offensive edit

answered 2012-08-06 07:25:53 +0800

onsir gravatar image onsir
132 2

i has try like this

for (Object item : listUnitPrice.getItems()) {
                listUnitPrice.renderItem((Listitem) item);
                for (Object cell : ((Listitem) item).getChildren()) {
                    if (((Listcell) cell).getListheader() != null) {
                       
                        System.out.println("val = " + ((Doublebox)(((Listitem)cell).getChildren().get(1))).getValue());
                        }

                    }
               }


get error
 java.lang.ClassCastException: org.zkoss.zul.Listcell cannot be cast to org.zkoss.zul.Listitem
 

link publish delete flag offensive edit

answered 2012-08-07 03:15:08 +0800

onsir gravatar image onsir
132 2

i'm not solved,
Is there another way
this
tractrace complete error

java.lang.ClassCastException: org.zkoss.zul.Listcell cannot be cast to
org.zkoss.zul.Listitem
        at controller.zk.UnitPriceController.onBtnClickSave(UnitPriceController.java:260)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.zkoss.zk.ui.event.GenericEventListener.onEvent(GenericEventListener.java:88)
        at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2741)
        at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2712)
        at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2653)
        at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136)
        at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:308)
        at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:331)
        at org.zkoss.zk.ui.AbstractComponent$ForwardListener.onEvent(AbstractComponent.java:3179)
        at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2741)
        at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2712)
        at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2653)
        at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136)
        at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1699)
        at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1484)
        at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1201)
        at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:558)
        at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:456)
        at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:464)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)
Aug 07, 2012 9:07:24 AM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1348


SEVERE: >>java.lang.NullPointerException
>>      at controller.zk.UnitPriceController.onBtnClickSave(UnitPriceController.java:342)
>>      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>>      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>      at java.lang.reflect.Method.invoke(Method.java:601)
>>      at org.zkoss.zk.ui.event.GenericEventListener.onEvent(GenericEventListener.java:88)
>>      at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2741)
>>      at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2712)
>>      at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2653)
>>      at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136)
>>      at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:308)
>>      at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:331)
>>      at org.zkoss.zk.ui.AbstractComponent$ForwardListener.onEvent(AbstractComponent.java:3179)
>>      at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:2741)
>>      at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2712)
>>      at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:2653)
>>      at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:136)
>>      at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1699)
>>      at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1484)
>>      at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1201)
>>      at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:558)
>>      at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:456)
>>      at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:464)
>>      at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
>>      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
>>      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
>>      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
>>      at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
>>      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
>>      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
>>      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
>>      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
>>      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
>>      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
>>      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
>>      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
>>      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
>>      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
>>      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
>>      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
>>      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
>>      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
>>      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
>>      at java.lang.Thread.run(Thread.java:722)

link publish delete flag offensive edit

answered 2012-08-07 09:26:27 +0800

onsir gravatar image onsir
132 2

thanks, solved

link publish delete flag offensive edit

answered 2012-09-12 21:19:56 +0800

kenshin gravatar image kenshin
18 1

Hi, how solved problem??

link publish delete flag offensive edit

answered 2012-09-13 02:00:52 +0800

onsir gravatar image onsir
132 2

try this

for (Object item : listUnitPrice.getItems()) {
                listUnitPrice.renderItem((Listitem) item);
                for (Object cell : ((Listitem) item).getChildren()) {
                    if (((Listcell) cell).getListheader() != null) {
  
 
                                      if (innercell instanceof Doublebox ){
                                            
                                            if (((Listcell) cell).getListheader().getColumnIndex() == 2) {
                                                  valuePrice=new BigDecimal(((Doublebox)innercell).getValue());
                                            }
}
}

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-08-06 05:14:40 +0800

Seen: 313 times

Last updated: Sep 13 '12

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