Hi All,
Please help me with what I want to do.
I have this scenario:
- I display a list of assets to users.
- User selects an asset and then clicks add item
- On my requestmapping, during GET operation. I use the service class to check if indeed this asset still exist in DB
- If not, user should be notified by a message. I use the form:error tag
My problem is when I add the error object in the method signature, I got this error Errors/BindingResult argument declared without preceding model attribute
@RequestMapping(value = "/addItemsToAsset.htm", method = RequestMethod.GET)
    public String setupForm(@RequestParam("assetID") Long assetID,
            Errors error, ModelMap model) {
        AssetItemVo voAsset = null;
        if (assetID != null && assetID != 0) {
            //Get data for asset from DB using assetID
            List<AssetDraftTempVo> lstDraft = service.getAssetDraftByLngID(assetID);
            if (lstDraft.size() == 0) {
                voAsset = new AssetItemVo();
                // I wanted to add validation here.  If no data for asset id is found, I would like to add an error to the error object
                error.reject("123","Unable to find info for the asset in the database.");
            } else {
                AssetDraftTempVo voDraft = lstDraft.get(0);
                voAsset = new AssetItemVo();
                voAsset.setStrPlant(voDraft.getStrPlant());
                .
                . /*other DTO property here*/
                .
            }
        }
        model.put("assetItemDetail", voAsset);
        return "additemstoasset";
    }
My goal is that during the display of the form, I wanted to populate the error object right away (if there is an error)
Here's my form for clarity.
<form:form modelAttribute="assetItemDetail"  method="post">
    <div id="error_paragraph">
        <form:errors path="*" cssClass="errors" />
    </div>
</form:form>
To get past the error, I manually change the method signature and added the model attribute but it still cannot populate the form:error tag
@RequestMapping(value = "/addItemsToAsset.htm", method = RequestMethod.GET)
public String setupForm(@RequestParam("assetID") Long assetID,
        @ModelAttribute("assetItemDetail") AssetItemVo voAssetData, Errors error,
        ModelMap model) 
Please help..