Thanks for responding.

The code I did send before is simplified, and translated to english:

The equivalents classes are:
Grupo = Group
Solicitante = Person

here is:
public class PanelGrupo extends Panel {

    private AsignacionModel asignacionModel;
    private WebMarkupContainer listContainer;
    private WebMarkupContainer resultadoContainer;
    private CompoundPropertyModel<Grupo> cpmGrupo;
    private ListView<Solicitante> lvSolicitantes;
    private Label resultLabel;
    public PanelGrupo(String id, Grupo g) {
        super(id);


        final List<CongregacionOfertante> listCong =
CongregacionOfertante.findAll(null);


        final Model<String> resultModel = new Model<String>("");

        cpmGrupo = new CompoundPropertyModel<Grupo>(g);

        lvSolicitantes = new ListView<Solicitante>("solicitante",
g.getSolicitanteList()) {
            @Override
            protected IModel getListItemModel(final IModel listViewModel,
final int index) {
                return new
CompoundPropertyModel(super.getListItemModel(listViewModel, index));
            }

            @Override
            protected void populateItem(ListItem<Solicitante> item) {
                final Solicitante s = item.getModelObject();

                ChoiceRenderer<CongregacionOfertante> crCongs = new
ChoiceRenderer<CongregacionOfertante>("nombre", "idCong");
                DropDownChoice<CongregacionOfertante> ddcCongs =
                        new
DropDownChoice<CongregacionOfertante>("congregaciones",
                        new
PropertyModel<CongregacionOfertante>(item.getModel(), "congOfertante"),
listCong, crCongs);

                item.add(new Label("nombre"));
                item.add(new Label("telefono"));
                item.add(new Label("edad"));
                item.add(new Label("sexo"));
                item.add(new Label("pubPre"));
                item.add(new Label("parentesco"));
                item.add(new Label("sordoOyente"));
                item.add(new Label("equipoDormir"));
                item.add(ddcCongs);
                item.add(new TextField("idOferta", Integer.class));
                item.add(new TextField("observaciones", String.class));

                item.add(new CheckBox("descartado", new
PropertyModel<Boolean>(s, "descartado")));

            }
        };

        add(new Label("id_grupo", g.getIdGrupo().toString()));
        add(new Label("nombre_congregacion", new
Model<String>(g.getCongregacion().getNombre())));



        Form f = new Form("formSolicitantes", cpmGrupo) {
        };


        Button deleteButton = new Button("eliminarGrupo") {
            @Override
            public void onSubmit() {
                Grupo g = cpmGrupo.getObject();
                EntityManager em = null;
                try {
                    em = DBManager.getEntityManager();
                    g = em.find(Grupo.class, g.getIdGrupo());
                    em.getTransaction().begin();
                    em.remove(g);
                    em.getTransaction().commit();
                } catch (OptimisticLockException e) {
                    Logger.getLogger(PanelGrupo.class).error("Error al
eliminar grupo " + g.getIdGrupo(), e);
                } finally {
                    em.close();
                }
                super.onSubmit();
            }
        };

        deleteButton.add(new AttributeModifier(
                "onclick", new Model("if(!confirm('¿Está seguro de eliminar
todo el grupo?')) return false;")));

        f.add(deleteButton);
        f.add(new Label("transporte", g.getTransporte() ? "Sí" : "No"));
        f.add(new Label("fechaLlegada"));
        f.add(new Label("fechaSalida"));
        f.add(new Label("adjunto", new
Model<String>(g.getAdjunto().getNombreArchivo())));
        f.add(new Label("comentarios"));
        f.add(new Label("mensajeCorreo", new
Model<String>(g.getAdjunto().getCorreo().getMensaje())));

        resultadoContainer = new WebMarkupContainer("resultadoContainer");
        resultadoContainer.setOutputMarkupId(true);

        resultLabel = new Label("resultado", resultModel);
        resultadoContainer.add(resultLabel);
        add(resultadoContainer);


        listContainer = new WebMarkupContainer("solicitantes");
        listContainer.setOutputMarkupId(true);
        listContainer.add(lvSolicitantes);

        f.add(listContainer);

        AjaxButton cancelButton = new AjaxButton("cancelar", new
Model<String>("Cancelar")) {
            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
                Grupo g = Grupo.findById(cpmGrupo.getObject().getIdGrupo());
                cpmGrupo.setObject(g);
                resultModel.setObject("");
                target.add(resultadoContainer);
                target.add(listContainer);
                super.onSubmit();
            }

            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form) {
                throw new UnsupportedOperationException("Not supported
yet.");
            }
        };

        Button saveButton = new Button("guardar", new
Model<String>("Guardar")) {
            @Override
            public void onSubmit() {

                Grupo g = (Grupo) cpmGrupo.getObject();

                try {
                    DBManager.saveWithLocking(g, false);
                    resultModel.setObject("Se ha guardado exitosamente.");
                    resultLabel.add(new AttributeModifier("class", new
Model(" green")));
                } catch (OptimisticLockException e) {
                    resultModel.setObject("El grupo había sido editado
préviamente. Se cargó la información que está en la base de datos.");
                    resultLabel.add(new AttributeModifier("class", new
Model(" red")));
                } finally {
                    g = Grupo.findById(g.getIdGrupo());
                    cpmGrupo.setObject(g);
                    lvSolicitantes.setList(g.getSolicitanteList());
                }
                super.onSubmit();
            }
        };
        cancelButton.setDefaultFormProcessing(false);

        f.add(cancelButton);
        f.add(saveButton);
        add(f);

    }
}

Thanks!

2012/8/13 Bertrand Guay-Paquet <[email protected]>

> Hi,
>
>
> On 13/08/2012 12:13 PM, Roger Palacios wrote:
>
>> Hi every all.
>>
>> This is my first mail in wicket mailing list.
>>
> Welcome!
>
>
>  I want to update the groups doing ajax submits. I tried using ListView,
>> but, I dont know why, when I click 'save' button the changes are reflected
>> on in the first group panel, if I update any other group and click 'save'
>> the Group object is not updated.
>>
> I'm a little bit confused... What is the "first group panel" ? Is it the
> first table row? I also don't understand the relation with the other page
> you presented with the filtering.
>
> Could you show the java side of the panel as well? It would help to
> understand the problem.
>
> Bertrand
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: 
> users-unsubscribe@wicket.**apache.org<[email protected]>
> For additional commands, e-mail: [email protected]
>
>

Reply via email to