TransWikia.com

Getting more data during a Post request using Spring / Thymeleaf

Stack Overflow Asked by Machtyn on November 16, 2021

I’m not really sure how to ask the question, but I’m going to try here.

I’ve got a list of actions that could happen to a subject. The user of my system needs to approve these actions and does so by selecting (checkboxes) these actions and then clicking the Approve button. Some of these action might require extra data, so a new page is presented to the user. The user enters that new data. Then the backend sends the whole package off to the endpoint for modification on the database. Once completed, it will reload the page they were just on.

So this is how I have it setup:

  1. Approve button jumps to the following method:
@PostMapping("ApproveActions")
public RedirectView approveActions(ModelandView mav, @ModelAttribute("pendingActions") PendingActionsForm pendingActions) {

   boolean needsDetails = false;
   ActionForm actionForm = new ActionForm();

   // parse through each of the actions
   pendingActions.forEach(action -> {
      // verify if the action has been selected by the user.
      if (action.isSelected()) {
         // if needsDetails hasn't been set to true, 
         if (!needsDetails) {
            // check to see if it is one of the special actions that needs more info
            needsDetails = ActionTypes.NeedsDetails(action.typeId());
         }
         // build the data for the endpoint
         actionForm.addActionData(action);
      }
   });

   if (needsDetails) {
      // load the new page 
      rv.setUrl("/extraActionDetails");
      return rv; // This is not right, but it does get me to the new page.
      // get data 
      // return to this point with that new data
      actionForm.setExtraDetails(???);
   }

   actionService.ApproveActions(actionForm);
   RedirectView rv = new RedirectView();
   rv.setUrl("/subjects/" + pendingActions.getSubjectId() + "#actions-pending");
   return rv;
}

The problem I’m having is I don’t know how to do that part with // load the new page get data and return to this point with that new data. I’ve got the extra-details.jsp page built out. And it’s controller can be called. Does this question make sense? Are there any tutorials out there that address this situation?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP