Skip to content
Snippets Groups Projects
Commit e2ef9341 authored by Marnuri Nitish -'s avatar Marnuri Nitish -
Browse files

Add success message for create event

parent 3ebe19bb
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import polish_community_group_11.polish_community.event.models.viewmodel.EventForm;
import org.springframework.web.bind.annotation.*;
import polish_community_group_11.polish_community.event.models.Event;
......@@ -83,7 +84,7 @@ public class EventController {
@PostMapping("event/add")
public ModelAndView addEvent(@Valid @ModelAttribute("event") EventForm event,
BindingResult bindingResult, Model model,
Principal principal) throws SQLException {
Principal principal, RedirectAttributes redirectAttributes) throws SQLException {
ModelAndView modelAndView = new ModelAndView("event/add-event");
if(bindingResult.hasErrors()) {
modelAndView.addObject(model.asMap());
......@@ -97,6 +98,7 @@ public class EventController {
throw new NullPointerException("New event is empty or null");
}
eventService.addNewEvent(event.processEventForm(),principal.getName());
redirectAttributes.addFlashAttribute("successMessage", "Event created successfully!");
modelAndView.setViewName("redirect:/event");
}
return modelAndView;
......
......@@ -36,5 +36,8 @@
</div>
</div>
<script src="/js/event/event.js"></script>
<script th:if="${successMessage}">
alert("Event created successfully");
</script>
</section>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment