0

Re-render items in a combobox when model changes

asked 2013-07-05 09:35:46 +0800

Neus gravatar image Neus
1415 14

updated 2013-07-05 11:16:25 +0800

Hi, I have this:

<combobox id="FiltroContadores" hflex="true" model="@load(vm.movimientos)" itemRenderer="@load(vm.rendererFiltroContadores)"/>

When model changes, itemRenderer is not called and combobox empties.

How can I re-render its items?

I tried calling ListDataEvent when model changes but I don't know if the code is wrong becuase items are not rerendered (I have a System.out.println in the renderer and it is not called):

new ListDataEvent(FiltroContadores.getModel(), ListDataEvent.CONTENTS_CHANGED, -1, -1);
new ListDataEvent(FiltroEquipos.getModel(), ListDataEvent.CONTENTS_CHANGED, -1, -1);
new ListDataEvent(FiltroInstalaciones.getModel(), ListDataEvent.CONTENTS_CHANGED, -1, -1);

Thank you

EDIT: This is the code where I get the list "movimientos"

@GlobalCommand("obtenerMovimientosConsulta")
@NotifyChange("movimientos")
public void obtenerMovimientosConsulta(){
    String fromYear = "";
    String fromMonth = "";
    String fromDay = "";
    String toYear = "";
    String toMonth = "";
    String toDay = "";
    fromYear = funciones.Field(fechasCriteriosSeleccion.getDBDesde().getText(), "/", 3);
    fromMonth = funciones.Field(fechasCriteriosSeleccion.getDBDesde().getText(), "/", 2);
    fromDay = funciones.Field(fechasCriteriosSeleccion.getDBDesde().getText(), "/", 1);
    toYear = funciones.Field(fechasCriteriosSeleccion.getDBHasta().getText(), "/", 3);
    toMonth = funciones.Field(fechasCriteriosSeleccion.getDBHasta().getText(), "/", 2);
    toDay = funciones.Field(fechasCriteriosSeleccion.getDBHasta().getText(), "/", 1);
    listaMovimientos = instalacionDAO.findMovimientos(codigosInstalaciones, fromYear, fromMonth, fromDay, toYear, toMonth, toDay);
}

And this is the renderer:

class AvoidingDuplicateRenderer implements ComboitemRenderer<Object> {
    private String _type;
    private List<String> _rendered = new ArrayList<String>();
    @Override
    public void render(Comboitem item, Object data, int index)throws Exception {
        Movimiento m = (Movimiento)data;
        String label = "";
        if("contador".equals(_type)){
            label = m.getNombreContador();
        }else if("equipo".equals(_type)){
            label = m.getNombreEquipo();
        }else if("instalacion".equals(_type)){
            label = m.getNombreInstalacion();
        }
        if (_rendered.contains(label)) {
            item.setParent(null);
            item.detach();
        } else {
            item.setLabel(label);
            _rendered.add(label);
        }
        System.out.println("renderer");
    }
    public void setType (String type) {
        _type = type;
    }
}
delete flag offensive retag edit

Comments

How you wrote the code can you share your viewmodel

sjoshi ( 2013-07-05 10:49:38 +0800 )edit

@shoshi, I edited the question to add some data. As you can see I have a System.out.println inside the renderer. And when model change it is not called.

Neus ( 2013-07-05 11:14:02 +0800 )edit

When model going to change is you Notify your model List

sjoshi ( 2013-07-05 14:19:24 +0800 )edit

Why are you using MVVM and renderers?

davout ( 2013-07-05 15:55:20 +0800 )edit

I don't know hot to do the same I'm doing in the renderer with MVVM

Neus ( 2013-07-08 08:06:50 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-07-08 11:09:04 +0800

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

Here are two examples for how combobox work... zk-combobox-with-item-rendered

zk-combobox-with-selectoption

May be this will help you to get answer.

link publish delete flag offensive edit

Comments

nicely done.

nsharma ( 2013-07-09 11:48:54 +0800 )edit

Thank you sjoshi

Neus ( 2013-07-12 08:57:13 +0800 )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-07-05 09:35:46 +0800

Seen: 102 times

Last updated: Jul 08 '13

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