I do not know how to move forward with this, to see if someone gives me a hand:)
In the modal that I see in the image several loaded credentials will appear. Each credential can be edited or deleted and I'm having architectural problems to do the edit (I'm new with Spring and Hibernate).
When clicking on edit I made the top modal replaced with a new one with 3 inputs to make the edit:
... from here I do not know how I could go and that's where I need help.
What I did was this:
// Editar credencial de un FisicHost
$("#credentialsTable").on('click',"button[id^='edi-']", (e) => {
$('#credentialsModal').modal('hide');
$('#editModal').modal('show');
var credentialId = e.target.id;
var newUser = $('#newUser').val();
var newPass = $('#newPass').val();
var newNotes = $('#newNotes').val();
$.post( "/fisicHost/" + credentialId + "/credentials/update", data => {
console.log(data);
});
});
It occurred to me to take the value of the 3 inputs and then make a post to the controller with those 3 values + the credential ID to edit ...
// Método para actualizar credenciales
@RequestMapping(value = "/fisicHost/{id}/credentials/update", method = RequestMethod.POST)
public void updateCredential(@PathVariable(value = "id") String credId){
String[] parts = credId.split("-");
int id = Integer.parseInt(parts[1]);
Credential credential = credentialService.getCredentialById(id);
credentialService.update(credential);
}
From here I get questions like:
How should I send those 3 values of the 3 inputs? If you look at the post that I do, in the URL I'm only sending the ID of the credential I want to update, I do not know how to send those 3 values of inputs to validate them in the controller (and I do not want to send them in the URL as with ID of the credential)!
And second ... once received by the controller and made the validations, how do I return the updated data of the controller to the view ??
Any help, explanation will be more than welcome.
Thank you very much everyone