I'm developing a web application using PlayFramework, and I'm having a problem clicking the command I would like to display an alert and not redirect the page as it is doing, redirecting to a blank screen. Instead, just show the alert that the command was sent and keep the current page on the screen.
My html page where I send the commands: where in the datatable I have the commands activate, deactivate and restart, these are the buttons where it is to send the command and only show an alert
<div class="panel-body">
<ul class="list-group">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<i class="fa fa-cubes"></i> Detalhes Patch panels
</h3>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Patch panel</th>
<th>MAC</th>
<th>IP</th>
<th>Número de portas</th>
<th>Status</th>
<td></td>
</tr>
</thead>
<tbody>
#{list items:t.patchpanels, as:'p'}
<tr>
<td>${p.nome}</td>
<td>${p.mac}</td>
<td>${p.ip}</td>
<td>${p.numPortas}</td>
<td>${p.status}</td>
<td><center>
<!-- Adicionado a função para enviar o comando do MQTT-->
<!-- Adicionado a função para enviar o comando do MQTT -->
<a href="@{comandosMqtt.ativar(p.ip, '0')}"><span class="btn btn-success btn-xs acaomqtt" > Ativar </span></a>
<a href="@{comandosMqtt.reiniciar(p.ip, '0')}"><span class="btn btn-warning btn-xs acaomqtt" > Reiniciar </span></a>
<a href="@{comandosMqtt.desativar(p.ip, '0')}"><span class="btn btn-danger btn-xs acaomqtt"> Desativar </span></a>
<a href="@{patchpanels.detalhesPatchpanel(p.id)}"><span class="btn btn-primary btn-xs"> Detalhes </span></a>
</center></td>
</tr>
#{/list}
</tbody>
</table>
</div>
</div>
</div>
</div>
</ul>
</div>
When I click on the command button it the MQTT class:
public class ComandosMqtt extends Controller {
@AuditoriaOctopus
public static void ativar(String ip, String porta, String comando) throws MqttException {
Mqtt mqtt = Mqtt.getInstance();
mqtt.comandoMqtt(ip, porta, "active"); //envia os valores como parâmetro para a função
//renderJSON("Ativado");//mostra apenas o IP na tela, é necessário alterar para poder mostrar novamente a página recarregada
}
@AuditoriaOctopus
public static void reiniciar(String ip, String porta, String comando) throws MqttException {
Mqtt mqtt = Mqtt.getInstance();
mqtt.comandoMqtt(ip, porta, "restart");
//renderJSON("Reiniciado");
}
@AuditoriaOctopus
public static void desativar(String ip, String porta, String comando) throws MqttException {
Mqtt mqtt = Mqtt.getInstance();
mqtt.comandoMqtt(ip, porta, "deactive");
//renderJSON("Desativado");
}
public ComandosMqtt(String ip, String porta) {
try {
Mqtt.getInstance();
} catch (MqttException e) {
e.printStackTrace();
}
}
}