I am working with Spring. I have one status button which changes the status of my program, i.e if I press that button my status become 1,2,3… The status gets stored in the database and program redirects to another page.
I want to show the changed status notification at the redirected page for a small amount of time, i.e. if program redirected to another page than it should show an alert anywhere on that page and the alert will then hide after some time.
Jsp button which changes the status:
<button onclick="statusClicked(${caseInfo.id},2,'Final')">Mark as Final</button>
This button will change status to 2.
jQuery function:
function statusClicked(caseId,flowId,status){ jConfirm("Are you sure to make the case '" + status + "'?", "Confirm Dialog", function(r) { if (r) { $("#statusCaseId").val(caseId); $("#statusFlowId").val(flowId); $("#statusCaseIdForm").submit(); } });
After this statusCaseIdForm
will get submitted along with value of flowId
There are many such buttons which changes the status of program
Controller class code:
@RequestMapping(value = "/updateFlow", method = RequestMethod.POST) public ModelAndView updateFlowGet(@RequestParam Integer caseId,@RequestParam Integer flowId) { ClientService clientService = ServiceLocator.getClientService(); MasterService masterService = ServiceLocator.getMasterService(); CreditCase creditcase =clientService.getCase(caseId); WorkflowStatus workStatus=masterService.getworkflowStatus(flowId); creditcase.setStatusId(flowId); creditcase.setStatusName(workStatus.getName()); masterService.addCreditCase(creditcase); ModelAndView model = new ModelAndView("redirect:/Dashboard"); return model; }
Here i am updating my database with the status value And redirecting it to dashboard. I want to show the alert notification at the dashboard for a small period of time.
Answer
Why don’t you just add the flowId
to your ModelAndView
, then using JSTL in your page to display the message:
<div id="warning"> <c:choose> <c:when test="${flowId eq 1}">This is the message for 1</c:when> <c:when test="${flowId eq 2}">This is the message for 2</c:when> <c:when test="${flowId eq 3}">This is the message for 3</c:when> </c:choose> </div>
After that… use jQuery to remove the div after x amount of seconds.