Announcement Announcement Module
Collapse
No announcement yet.
SimpleFormController onSubmit method (Solved) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SimpleFormController onSubmit method (Solved)

    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.

    Code:
    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.

    Code:
    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?

  • #2
    Problem solved!

    My fault, I used wrong import for BindException, so this method did not override super class's one.

    Comment

    Working...
    X