In a web application it is not complicated, execute alert(mensaje)
in the view and you will have a popup with the text that you send in the variable mensaje
.
If you need more personalization, you can create a JSP modal or use JQuery Dialog
To achieve this it is important to know WHERE everything is executed (here a summary of the flow of the request skipping the service, business and bbdd layers that any web app has:
- Send the order from to perform the query (CLIENT - JavaScript)
- Perform the query on the server side (SERVER - Java)
- Get an answer (SERVER - Java)
- Send the result to the view (SERVER - Java)
- If successful shows the result of the query (CLIENT - JavaScript)
- If it fails it shows an error message (CLIENT - JavaScript)
As you can see in the final division, in the same way that you send the results of the successful query, you can also send the error message (or null failing) to the view.
An example (very simplified and with ajax call ) would look like this:
$.get("/listaTodosLosObjetos",
{ "variable": valor } ).done(function( resultado ) {
// error
if(resultado == null) {
alert("No se ha encontrado ningun registro en la base de datos");
} else {
// la consulta ha tenido exito
// muestra la informacion como hasta ahora
}
});
ADDED: The above is the simple version, you should optimally throw exceptions during the process, launch them in the bean and collect them with .fail
, you can also perform default actions with .default
in the view:
$.get("/listaTodosLosObjetos", {
"variable": valor
})
.done(function( resultado ) {
// la consulta ha tenido exito
// muestra la informacion como hasta ahora
})
.fail(function() {
alert("No se ha encontrado ningun registro en la base de datos");
})
.always(function() {
// acciones comunes, como por ejemplo,
// limpiar algun campo o reiniciar variables.
valor = "";
});