0
I have a dataTable
with the data in front of each given one button, when I click one button dialog
is opened so that I can edit this data, but I cannot take the object that was selected to pass as parameter pro method that makes the editing.
How do I get the linha(objeto)
selected from the table by clicking the edit button?
I’m doing it this way:
<p:dialog header="Pausar Atividade" widgetVar="dlg3"
modal="true" height="300" width="700">
<p:panelGrid columns="2" cellpadding="4" style="width:100%;margin-top:20px" columnClasses="rotulo, campo">
<p:outputLabel value="Motivo" />
<h:panelGroup>
<p:inputTextarea rows="5" cols="30" counter="display1"
maxlength="255" counterTemplate="{0} Caracteres Restantes."
autoResize="false" style="width:70%" value="#{tarefaBean.tarefa.comentario}" />
<br />
<h:outputText id="display1" />
</h:panelGroup>
</p:panelGrid>
<p:commandButton value="Pausar Tarefa" style="margin-left:25%;margin-top:20px;width:50%" actionListener="#{tarefaBean.pausarTarefa}" update=":msgGlobal: frmPrin"/>
</p:dialog>
The button in the datatable:
<p:column headerText="Ações" style="text-align:center">
<p:commandButton icon="ui-icon-check" title="Finalizar" onclick="PF('dlg4').show();" />
<p:commandButton icon="ui-icon-pause" title="Pausar" onclick="PF('dlg3').show();" />
</p:column>
Bean method:
public void pausarTarefa(){
try {
tarefa.setStatus("Pausado");
tarefa.setDataFim(new Date());
TarefaDAO tarefaDAO = new TarefaDAO();
tarefaDAO.editar(tarefa);
FacesUtil.adicionarMsgInfo("Solicitação Enviada com Sucesso");
} catch (RuntimeException e) {
FacesUtil.adicionarMsgErro("Erro ao Enviar Solicitação!");
e.printStackTrace();
}
}
When I put
pausarTarefa(Tarefa tarefa)
of error. When I leave without works, but editing gets a little crazy, if I give an F5 it goes back to the previous state, ie with the data before editing– Diego
You do not need to add a parameter, it is only within your method to use the objectSelected.
– Rafael
I’m using, but it edits if I give F5 it goes back to the previous state, if I give another F5 it goes back to the edited and so goes.
– Diego
your bean this @Viewscoped?
– Rafael
Yes, I have to change it?
– Diego
Then the problem should be in the method that fills the datatable list. It should not be updating the list or datatable correctly.
– Rafael
I made a
Sysout
To print the list in the DAO and each F5 it brings a different list, updated and old. How is this possible if in the database is only the updated data?– Diego
Well then your problem is in your method or with you are calling it in datatable, I saw you asked another question I will answer by there, if this question solved your problem mark it as correct.
– Rafael