0

I am converting my controllers to annotated style controllers in spring mvc.

Basically I do this in the old style controller simpleformcontroller.

protected Map referenceData(HttpServletRequest request) throws Exception { 
    Map referenceData = new HashMap(); 
     List<ItemVo> lstItem1 = eqrManager .searchAllEqptCondQualItems("A1", "BOXES");     List<ItemVo> lstItem2 = eqrManager.searchAllEqptFullQualItems("A2", "CANNED_GOODS");     referenceData.put("BOX_ITEMS", lstItem1);
referenceData.put("CANNED_ITEMS", lstItem2); 
return referenceData; 
}

I do below way by taking model as a input argument,But it is calling only one time,How can i make below method should call everytime when form submission happens.

@RequestMapping(method=RequestMethod.GET) public void setUp(Model model) {  
   model.addAttribute("CANNED_ITEMS", eqrManager.searchAllEqptFullQualItems("A2", "CANNED_GOODS"))          .addAttribute("BOX_ITEMS", eqrManager.searchAllEqptCondQualItems("A1", "BOXES")); } 

Regards,

Raj

1 Answer 1

1

You can use @ModelAttribute-annotated method as a replacement of referenceData():

@ModelAttribute("CANNED_ITEMS")
public List<ItemVo> cannedItems() {
    return eqrManager.searchAllEqptFullQualItems("A2", "CANNED_GOODS");
}

@ModelAttribute("BOX_ITEMS")
public List<ItemVo> boxItems() {
    return eqrManager .searchAllEqptCondQualItems("A1", "BOXES");
}

These methods are called automatically for each request handled by the controller where they're defined, and their results are addded to the model.

Sign up to request clarification or add additional context in comments.

2 Comments

How can i call this in single method with every form submission.
I tried that before its working,But i want to define single method returning all my iniital objects to load my form,it should call every request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.