2

notifychange to grid that is inside a row of another grid.

asked 2013-12-27 08:39:59 +0800

juancar gravatar image juancar
33 2

updated 2013-12-30 04:36:47 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

I try to do the maintenance of a grid that is inside a row of another grid. But I do not manage to do the @notifychange when insert or eliminate rows of the second grid.

I have tried in spite of putting

 @NotifyChange({ "listaLineaDetalleFactura[0].descuentos.discount" })

and it works correctly, but what I need is that the grid refreshes himself in any row, not only in the first occurrence

  @NotifyChange({ "listaLineaDetalleFactura[IDX].descuentos.discount" })

If I write to level of the first grid it notifies well the changes but all the rows of the grid are closed and this it is not the wished effect either.

The code that I need to correct is:

@Command
@NotifyChange({ "listaLineaDetalleFactura[0].descuentos.discount" })
public void incluirDtoDetalle(@BindingParam("nroLinea") Integer numLin){
   int i = numLin.intValue();
   listaLineaDetalleFactura.get(i).getDescuentos().getDiscount().add(new DiscountType());
}
delete flag offensive retag edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2013-12-30 07:14:40 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...

updated 2014-01-07 13:50:47 +0800

Do this where you add or delete the row, where idx is the first grid row that is affected.

@Command
public void incluirDtoDetalle(@BindingParam("nroLinea") Integer numLin){
   int i = numLin.intValue();
   listaLineaDetalleFactura.get(i).getDescuentos().getDiscount().add(new DiscountType());
   BindUtils.postNotifyChanged(null,null,listaLineaDetalleFactura.get(i),"descuentos");
}
link publish delete flag offensive edit

Comments

does this work now (edited after post of example)

chillworld ( 2014-01-07 13:49:55 +0800 )edit

Thank you very much. Your collaboration has used me as great help

The command BindUtils.postNotifyChanged(null,null,listaLineaDetalleFactura.get(i),"descuentos") does the effect that I need

juancar ( 2014-01-08 07:29:31 +0800 )edit

Your welcome, if you need other help let us know. Do you want to accept the answer as correct? Thx in advance

chillworld ( 2014-01-08 07:38:58 +0800 )edit
0

answered 2014-01-02 10:12:58 +0800

juancar gravatar image juancar
33 2

I have tried with BindUtils.postNotifyChange(null, null, this, "listaLineaDetalleFactura["+numLin+"].descuentos.discount");

but it does not work.

It does not even work putting the occurrence directly BindUtils.postNotifyChange(null, null, this, "listaLineaDetalleFactura[0].descuentos.discount");

@Command public void incluirDtoDetalle(@BindingParam("nroLinea") Integer numLin){ listaLineaDetalleFactura.get(numLin).getDescuentos().getDiscount().add(new DiscountType()); BindUtils.postNotifyChange(null, null, this, "listaLineaDetalleFactura[0].descuentos.discount"); }

link publish delete flag offensive edit

Comments

Working on sample program now, more info will come

chillworld ( 2014-01-06 13:37:17 +0800 )edit
0

answered 2014-01-06 14:12:42 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...

updated 2014-01-07 07:50:55 +0800

Oke following example shall work :

First simple pojo class :

package be.chillworld;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author chillworld
 */
public class Person {
    private int id;
    private String naam;
    private List<Person> childs = new ArrayList<Person>();

    public Person(int id) {
        this.id = id;
        naam = "test " + id;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setNaam(String naam) {
        this.naam = naam;
    }

    public String getNaam() {
        System.out.println("asked getter (naam) of "+ id);
        return naam;
    }

    public List<Person> getChilds() {
        System.out.println("asked getter (childs) of "+ id);
        return childs;
    }

    public void setChilds(List<Person> childs) {
        this.childs = childs;
    }

    public boolean addChild(Person person) {
        return childs.add(person);
    }

    @Override
    public String toString() {
        return "Person{" + "id=" + id + ", name=" + getNaam() + '}';
    }
}

then the IndexVM:

package be.chillworld;

import java.util.ArrayList;
import java.util.List;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;

/**
 *
 * @author chillworld
 */
public class IndexVm {

    private List<Person> persons;
    int i;

    public IndexVm() {
        System.out.println("starting creating list");
        persons = new ArrayList<Person>();
        for (i = 0; i < 100; i++) {
            Person person = new Person(i);
            person.addChild(new Person(++i));
            persons.add(person);
        }
        System.out.println("ending creating list");

    }

    public List<Person> getPersons() {
        return persons;
    }

    public void setPersons(List<Person> persons) {
        this.persons = persons;
    }

    @Command
    public void showIndex(@BindingParam("person") Person person) {
        System.out.println("changed name");
        person.setNaam("Chillworld");
        BindUtils.postNotifyChange(null, null, person, "naam");
    }

    @Command
    public void addChild(@BindingParam("person") Person person) {
        System.out.println("add child");
        Person child = new Person(++i);
        child.setNaam("new child");
        person.addChild(child);
        BindUtils.postNotifyChange(null, null, person, "childs");
    }
}

and at last the index.zul :

<?xml version="1.0" encoding="UTF-8"?>
<zk xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.zkoss.org/2005/zul"
xsi:schemaLocation="http://www.zkoss.org/2005/zul
                   http://www.zkoss.org/2005/zul/zul.xsd">
<window border="normal" closable="false"
        apply="org.zkoss.bind.BindComposer"
        viewModel="@id('vm') @init('be.chillworld.IndexVm')">
    <grid width="1000px" model="@load(vm.persons)">        
        <columns>            
            <column label="naam" /> 
            <column label="add child" />            
            <column label="childs" />        
        </columns>        
        <template name="model" >            
            <row>                
                <textbox value="@bind(each.naam)" /> 
                <button onClick="@command('addChild',person = each)" label="add child"/>                       
                <grid width="400px" model="@load(each.childs)">        
                    <columns>            
                        <column label="naam" />            
                        <column label="button" />        
                    </columns>        
                    <template name="model" var="item">            
                        <row>                
                            <textbox value="@bind(item.naam)" /> 
                            <button onClick="@command('showIndex',person = item)" label="change value"/>        
                        </row>        
                    </template>    
                </grid>           
            </row>        
        </template>    
    </grid>
</window>
</zk>

this gives as output (after startup) :

changed name
asked getter of 11
changed name
asked getter of 7
changed name
asked getter of 19

Sorry for late response. Hope this helps you and please vote if correct answer.

Greetz chill.

link publish delete flag offensive edit
Your answer
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
1 follower

RSS

Stats

Asked: 2013-12-27 08:39:59 +0800

Seen: 69 times

Last updated: Jan 07 '14

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