複数のビューにわたる単一の Bean の管理を処理するウィザードのようなコントローラーを作成しています。@SessionAttributes を使用して Bean を保存し、SessionStatus.setComplete() を使用して最終呼び出しでセッションを終了します。ただし、ユーザーがウィザードを放棄してアプリケーションの別の部分に移動した場合は、戻ったときに Spring に強制的に @ModelAttribute を再作成させる必要があります。例えば:
@Controller
@SessionAttributes("commandBean")
@RequestMapping(value = "/order")
public class OrderController
{
@RequestMapping("/*", method=RequestMethod.GET)
public String getCustomerForm(@ModelAttribute("commandBean") Order commandBean)
{
return "customerForm";
}
@RequestMapping("/*", method=RequestMethod.GET)
public String saveCustomer(@ModelAttribute("commandBean") Order commandBean, BindingResult result)
{
[ Save the customer data ];
return "redirect:payment";
}
@RequestMapping("/payment", method=RequestMethod.GET)
public String getPaymentForm(@ModelAttribute("commandBean") Order commandBean)
{
return "paymentForm";
}
@RequestMapping("/payment", method=RequestMethod.GET)
public String savePayment(@ModelAttribute("commandBean") Order commandBean, BindingResult result)
{
[ Save the payment data ];
return "redirect:confirmation";
}
@RequestMapping("/confirmation", method=RequestMethod.GET)
public String getConfirmationForm(@ModelAttribute("commandBean") Order commandBean)
{
return "confirmationForm";
}
@RequestMapping("/confirmation", method=RequestMethod.GET)
public String saveOrder(@ModelAttribute("commandBean") Order commandBean, BindingResult result, SessionStatus status)
{
[ Save the payment data ];
status.setComplete();
return "redirect:/order";
}
@ModelAttribute("commandBean")
public Order getOrder()
{
return new Order();
}
}
ユーザーが「getCustomerForm」メソッド (つまり、http://mysite.com/order ) をトリガーするアプリケーションに要求を行い、「commandBean」セッション属性が既に存在する場合、「getOrder」は呼び出されません。この状況で新しい Order オブジェクトが作成されるようにする必要があります。getCustomerForm で手動で再設定する必要がありますか?
考え?私が自分自身を明確にしていない場合はお知らせください。