title: Check For Modal Attribute Existence In Controller Method before adding
body: <p>I have a spring controller that I want a method to handle a certain request and then redirect to another one with keeping some value attached, so I will use RedirectAttributes on the first one and @ModalAttribute on the second, but the thing is I will not always have this modal attribute existing so I want to add it only if it exists.</p>
  
  <pre><code>@RequestMapping("/main")
  public String getMain(Model model,HttpSession session,@ModalAttribute List&lt;Loans&gt; loansList){
      if(session.getAttribute("user") != null){
          if(session.getAttribute("current_start")!=null){
              model.addAttribute("loans",loanDao.findAll((Integer) session.getAttribute("current_start")));
          } else {
              model.addAttribute("loans",loanDao.findAll(0));
              session.setAttribute("current_start",0);
          }
          model.addAttribute("loan",new Loan());
          model.addAttribute("countries",countryDao.findAll());
          model.addAttribute("types",typeDao.findAll());
          session.setAttribute("total_loans_number", loanDao.findCount());
          return "main";
      } else {
          return "redirect:index";
      }
  }
  </code></pre>
  
  <p>and the redirecting one one is </p>
  
  <pre><code>@RequestMapping(value = "/search")
  public String searchLoans(Model model,RedirectAttributes redirectAttributes,
                            @RequestParam String keyword){
      redirectAttributes.addAttribute("loansList",loanDao.findAll(keyword));
      return "redirect:/main";
  }
  </code></pre>
  
  <p>but here the @ModalAttribute fails because it sometimes does not exist,sometimes I request main with out the loansList, how to make a condition to add it only if it exists ? or how to do this correctly ?</p>