Reputation: 1476
Suppose this is admin portal, here the admin need to approve or block the users. I want to implement this functionality. This is how the page appear for admin, username and status will be fetched from database, now admin has two buttons either to activate or block the user or in next column admin can also delete that user. Now I got stucked here in scenario that I can fetch the username and status from database but for the column "activate/block" I need to give admin 2 buttons. Even that I can simply put while iterating user data from table, but my problem is that when admin click either active or block button, I need to have that corresponding username to write any logic. I know Java, Hibernate Spring but not too good in UI portion functionality, actually I used to do that in my alternative ways that is not good for learning purpose. I can implement but need idea or logic, how to approach toward this functionality in professional way and not in alternative ways . Even I can read new GUI technology like Ajax, Jquery etc.
Upvotes: 0
Views: 286
Reputation: 441
Onclick of activate button you make an ajax call to spring controller and pass user id/email in that call. spring controller will activate that user and return status as a Boolean true/false or a String "Success"/"Failure". then in UI side you read the status, if success then you change user status from inactive to active and button text from activate to deactivate.
$(function(){
var id = getUserIdHere;
$.get("${contextPath}/relativeControllerUrl",
{userId: id}, function(data) {
if(data=='Success') {
//change status & button text here;
}
});
});
Spring Controller:
@RequestMapping("/relativeControllerUrl")
public String @ResponseBody yourMethodName(@RequestParam Integer userId) {
boolean status = userService.activateUserById(userId);
return status?"Success":"Failure";
}
Upvotes: 1