tags:

views:

27

answers:

1

I am new to annotated controllers and i have a problem. Ive heard it is possible to navigate between forms using them, but cant achieve that.

Well probably I could use SWF but for whole project controllers are more suitable.

My controllers looks like this:

@Controller
public class AnDBChooseController {

 @RequestMapping("/dbchoose")
 public ModelAndView choose(@ModelAttribute("db") ComponentDB db){
  ModelAndView mv=new ModelAndView();
  switch(db.getDbAction()){
  case 1:   // dodanie komponentu
   if (db.getDbType().equals(ComponentDB.DB_CAPACITOR)){ 
    mv.addObject("capacitor",new Capacitor());
    mv.setViewName("addcapacitor");

   }else if (db.getDbType().equals(ComponentDB.DB_RESISTOR)){ 
    mv.setViewName("addresistor");

   }
   break;
  case 2:   // future
   break;
  case 3:   // future
   break;
  default:  // future
   break;

  }
  return mv;
 }
}

This controller should send me to addcapacitor.jsp

Secound controller (witch never starts)

@Controller
public class AnAddCapacitorController {

 ComponentParamTypeService paramService;

 @ModelAttribute("subclass")
 public ArrayList<ComponentParamType> getSubclasses(){
                System.out.println("I am here :]");
  return paramService.getParamsForType(ComponentParamType.SUBCLASS_CAPACITOR);
 }

 @RequestMapping("/addcapacitor")
 public String add(@RequestParam("capacitor")Capacitor capacitor){
  return "addcapacitordetails";
 }

 public ComponentParamTypeService getParamService() {
  return paramService;
 }

 public void setParamService(ComponentParamTypeService paramService) {
  this.paramService = paramService;
 }
}

Of course "I am here :]" never shows on console :(

How should change that so i am redirected to addcapacitor whitout loosing model parameters

Tahnks,

+1  A: 

You can have the methods return a String instead of a ModelAndView. And forward to the action.

@RequestMapping("/dbchoose")
 public String choose(@ModelAttribute("db") ComponentDB db, Model model){
  switch(db.getDbAction()){
  case 1:   // dodanie komponentu
   if (db.getDbType().equals(ComponentDB.DB_CAPACITOR)){ 
    mv.addAttribute("capacitor",new Capacitor());
    return "forward:/addcapacitor";   

   }else if (db.getDbType().equals(ComponentDB.DB_RESISTOR)){ 
    return "forward:/addresistor";   

   }
   break;
  case 2:   // future
   break;
  case 3:   // future
   break;
  default:  // future
   break;

  }
 }
John V.
thanks for the solution, works great now. For other ppl with same problem, remember to add .htm at the end of return :)return "forward:/addcapacitor.htm";Now back to coding :)
Marek
@Marek thats good to know. I guess I thought you wanted to chain controllers. But good to see you got it working
John V.
@John V. I wanted to chain them, it works just fine with 2 forms, doubt it would with more. Well if ill be forced to chain 3 or more ill have to use some dirty tricks i suppose. Thanks again :)
Marek