Search code examples
javajakarta-eezkjava-ee-5

zk framework memory grid


I use zk framework MVVM approach and want display grid with 1000-2000 rows per page.(It is really need for user) But it is a lot of information and every user will consume about 30Mb if i will save my grid model (List<Object>) in memory on server side. I decide what will be good just render this sort of information and clean memory on server side, but if i use this approach i should go to client side programming. (write js for ajax calls and etc.) Can't find good solution for this issue. What i should use auRequest, RowRender or Render script on client side or just null data after render grid?

UPD: ZUL

<grid apply="org.zkoss.bind.BindComposer"
      viewModel="@id('vm') @init('Pojo')"
      self="@define(content)" height="100%" width="100%">
      model="@load(vm.o)" emptyMessage="${c:l('empty_table')}"
      stubonly="true" onCreate="@command('clear')">
   <columns>
      ...cols...
   </columns>
   <template name="model">
      <row>
           <label value="@load(each.data)" />
      </row>
   </template>
</grid>

JAVA:

 public class Pojo {

     private List<Object> o;
     private Grid g;

     @Init
     public void init(){
        o = loadFromDaoOneHundredItems()
     }

     @AfterCompose
     public afterCompose(@ContextParam(ContextType.VIEW) Component view){
          g.setPageSize(1000);
     }
 }

UPD

    final Rows rs = new Rows();
    for (int i = 0; i < 1000; i++) {
        final Row r = new Row();
        r.appendChild(new Label("sdf"));
        r.appendChild(new Label("sdf"));
        r.appendChild(new Label("sdf"));
        rs.appendChild(r);
    }
    grid.appendChild(rs);
    ListModelList<Object> o = null;
    grid.setModel(o);

Solution

  • ZK provides many ways to handle your logic client side.
    At first you should read the communication part of the client-side zk manual.
    In addition, this awnser should be helpful.

    You should know, that model="@load(vm.o)" calls Grid.setModel(...)
    and saves a reference so that data will not be deleted by javas gc.

    So I think the only way to solve this, by still using MVVM even if it
    breaks the pettern as far as I understand MVVM, would be to call

    onCreate="@command('createRows',grid=self)"
    

    and add a method like

    @Command("createRows")
    public void createRows(@BindingParam("grid") Grid grid){
     //add rows manually here
    }
    

    But I have to say that for your task, I would prefer to use ZK MVC,
    cos of better readability/maintainability and more control cos of java.