tar
Aug 26th, 2005, 05:19 AM
Velocity does not get ModelAndView returned by SimpleFormController's onSubmit method. It means that those valuees are empty in this page which should come from model.
public class AddProductController extends SimpleFormController {
...................................
protected ModelAndView onSubmit(Object command, BindException errors) throws Exception {
//Product product = (Product)command;
//productService.saveProduct(product);
Map model = new HashMap();
model.put("products", productService.getAllProducts());
model.put("sort", "desc");
return new ModelAndView(this.getSuccessView(), model);
}
...................
}
Elsewhere in some other control I have similar code, which uses same view and there were no problem. Velocity got those objects from model.
public class DisplayProductsController implements ThrowawayController{
.................................
public ModelAndView execute() throws Exception {
List products;
if (sort.equalsIgnoreCase("asc"))
products = productService.getAllProducts(ProductService.ORDER _ASC);
else
products = productService.getAllProducts(ProductService.ORDER _DESC);
Map model = new HashMap();
model.put("products", products);
model.put("sort", sort);
return new ModelAndView("displayProducts", model);
}
....................
}
Whys is it thatway?
public class AddProductController extends SimpleFormController {
...................................
protected ModelAndView onSubmit(Object command, BindException errors) throws Exception {
//Product product = (Product)command;
//productService.saveProduct(product);
Map model = new HashMap();
model.put("products", productService.getAllProducts());
model.put("sort", "desc");
return new ModelAndView(this.getSuccessView(), model);
}
...................
}
Elsewhere in some other control I have similar code, which uses same view and there were no problem. Velocity got those objects from model.
public class DisplayProductsController implements ThrowawayController{
.................................
public ModelAndView execute() throws Exception {
List products;
if (sort.equalsIgnoreCase("asc"))
products = productService.getAllProducts(ProductService.ORDER _ASC);
else
products = productService.getAllProducts(ProductService.ORDER _DESC);
Map model = new HashMap();
model.put("products", products);
model.put("sort", sort);
return new ModelAndView("displayProducts", model);
}
....................
}
Whys is it thatway?