Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-2815

class cast exception when using a Boolean collection for MVVM

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 7.0.7
    • 7.0.5
    • None
    • Security Level: Jimmy
    • ZK 7.0.7

      I want with MVVM load and save the status of checkboxes as boolean value. When you save the state, reports ZK a class cast exception.
      I have created the following small example. This can be tested for example with ZK fiddle. After clicking on one of the checkboxes ZK reporting the error.

      "java.lang.Integer cannot be cast to java.lang.String"

      <?xml version="1.0" encoding="UTF-8"?>
      <zk>
      	<window id="win" title="Window ZK Checkboxes" border="normal" width="800px" height="600px" 
          		apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('pkg$.CheckVM')">
          	<vlayout id="winA" width="100%" children="@load(vm.listModel)">
         			<template name="children">
      	    		<hlayout row="@ref(each)" width="100%" children="@load(row.labels)">
      	    			<template name="children">
      	    				<checkbox label="@init(each)" onClick="@command('check_click')"
      	    						  checked="@load(row.states[forEachStatus.index]) @save(row.states[forEachStatus.index], after='check_click')"/>
      	    			</template>
      	    		</hlayout>
          		</template>
      	   	</vlayout>
          </window>
      </zk>
      
      import org.zkoss.zk.ui.*;
      import org.zkoss.zk.ui.event.*;
      import org.zkoss.zk.ui.util.*;
      import org.zkoss.zk.ui.ext.*;
      import org.zkoss.zk.au.*;
      import org.zkoss.zk.au.out.*;
      import org.zkoss.zul.*;
      import org.zkoss.bind.annotation.Command;
      
      public class CheckVM 
      {
          ListModelList< Val > lm_= new ListModelList< Val >();
          // hold checkbox state and label for one row.
          public class Val
          {
              public Val(Boolean[] boxes)     
              { 
                  boxes_= boxes; 
                  labels_= new ListModelList();   for (int i= 0; i< boxes_.length; ++i) labels_.add("Checkbox "+ i);
              }
      
              public Boolean[] getStates()                    { return boxes_; }
              public ListModel getLabels()                    { return labels_; }
      
              Boolean[] boxes_= null;
              ListModelList< String > labels_;
          }
      
          public CheckVM()
          {
              lm_.add(new Val(new Boolean[] { Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE }));
              lm_.add(new Val(new Boolean[] { Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.TRUE }));
          }
      
          @Command
          public void check_click()           {}
          public ListModel getListModel()     { return lm_; } 
      }
      

            DevChu DevChu
            khcyt khcyt
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 30 minutes
                30m