I have a problem in 'DataView' do 'Wicket' ... I add some files to this DataView, and so far so good, when I delete a file is that the problem, if I delete any file that does not it is the first rule ... but if I try to delete the first item it excludes all other low sequentially ... anyone has seen something?
follows my code below:
//Principal panel
private class PanelPrincipalAnexo extends WebMarkupContainer
{
public PanelPrincipalAnexo(String id)
{
super(id);
formUpload = getFormUpload();
add(formUpload);
formUpload.add(getDataViewAnexos("anexos"));
}
}
//creating the FormUpload
private FileUploadForm getFormUpload() {
return new FileUploadForm("formUpload", new PropertyModel<List<FileUpload>>(this, "uploads"));
}
private DataView<ProgramaAnexo> getDataViewAnexos(String id) {
return new DataView<ProgramaAnexo>(id, new AnexoProvider()) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(Item<ProgramaAnexo> item) {
item.add(new Label("tipoArquivo"));
item.add(new Label("nomeAnexo"));
item.add(new Label("tamanhoArquivoEmMB"));
item.add(getButtonRemove(item));
}
};
}
public AjaxSubmitLink getButtonRemove(Item<ProgramaAnexo> item) {
AjaxSubmitLink button = new AjaxSubmitLink("btnRemoverBem", form) {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit(AjaxRequestTarget target, Form form) {
actionRemoverKit(target,item);
}
};
return button;
}
private void actionRemoverKit(AjaxRequestTarget target,Item<ProgramaAnexo> item) {
ProgramaAnexo bemRemove=item.getModelObject();
int cont=0;
for(ProgramaAnexo bem:list)
{
if(bemRemove.getBem().getId().intValue()==bem.getBem().getId().intValue())
{
listaBensSelecionadosDireito.remove(cont);
break;
}
}
target.add(panelPrincipalAnexo);
}
THE HTML
<table width="98%" class="table table-hover"
style="table-layout: fixed;">
<thead>
<tr>
<th width="16%"></th>
<th width="16%">Tipo</th>
<th width="29%">Arquivo</th>
<th width="10%">Tamanho</th>
<th width="25%" class="text-left">Ações</th>
<th width="4%"></th>
</tr>
</thead>
<tbody>
<tr wicket:id="anexos">
<td width="16%"></td>
<td width="16%"><span wicket:id="tipoArquivo"></span></td>
<td width="29%"><span wicket:id="nomeAnexo"></span></td>
<td width="10%"><span wicket:id="tamanhoArquivoEmMB"></span></td>
<td width="25%" class="text-left">
<button wicket:id="btnExcluirAnexo"
title="Excluir"
class="btn btn-danger btn-sm"
id="btnRemoverBem"">
<i class="fa fa-minus"></i>
</button>
</td>
<td width="4%"></td>
</tr>
</tbody>
</table>
All right guys? So I managed to find the answer here. In fact the code is right, the problem was in HTML ... The code I was using was this: .
<button wicket:id="btnExcluirAnexo"
title="Excluir"
class="btn btn-danger btn-sm"
id="btnRemoverBem"">
<i class="fa fa-minus"></i>
</button>
I just removed the id in 'Button' and went on to iterate usually ... I do not know why this problem occurred, but hey, it worked :) .
<button wicket:id="btnExcluirAnexo"
title="Excluir"
class="btn btn-danger btn-sm"
I REMOVED THE ID HERE>
<i class="fa fa-minus"></i>
</button>
Thanks to everyone who posted a reply.