Lukasz Nadrowski
Lukasz Nadrowski

Reputation: 1

broadleaf override controller method

I'm new on broadleaf.

I have problem, I wanted to obscure the method that removes my order in admin:

I create controller :

public class NewOrderController extends AdminBasicEntityController {

    private static final Logger LOGGER = Logger.getLogger(NewOrderController.class);

    protected static final String SECTION_KEY = "order";

    @Override
    protected String getSectionKey(Map<String, String> pathVars) {
        if (super.getSectionKey(pathVars) != null) {
            return super.getSectionKey(pathVars);
        }
        return SECTION_KEY;
    }

    @Override
    @RequestMapping(
        value = {"/{id}/delete"},
        method = {RequestMethod.POST}
    )
    public String removeEntity(HttpServletRequest request, HttpServletResponse response, Model model, Map<String, String> pathVars, String id, EntityForm entityForm, BindingResult result, RedirectAttributes ra) throws Exception {

        LOGGER.info("wywołanie nadpisane metody: " + NewOrderController.class.toString());
        return "String";
    }


}

in applicationContext-admin.xml

add :

All the time it calls me the not overwritten method.

Upvotes: 0

Views: 150

Answers (1)

phillipuniverse
phillipuniverse

Reputation: 2045

When you create a controller, the bean must be in the servlet context, not in the root context. If you are modifying applicationContext-admin.xml then you are actually adding the bean to the root context.

Add your bean to applicationContext-servlet-admin.xml or add a new <component-scan> entry into applicationContext-servlet-admin.xml to scan your new bean.

One more thing: you likely do not want to override the entire AdminBasicEntityController and it looks like you just want to override /order/* methods. In that case, you should annotate your controller with @Controller and add an @RequestMapping for your section key like this:

@Controller
@RequestMapping("/" + SECTION_KEY)
public class NewOrderController extends AdminBasicEntityController {

    private static final Logger LOGGER = Logger.getLogger(NewOrderController.class);

    protected static final String SECTION_KEY = "order";

    @Override
    protected String getSectionKey(Map<String, String> pathVars) {
        if (super.getSectionKey(pathVars) != null) {
            return super.getSectionKey(pathVars);
        }
        return SECTION_KEY;
    }

    @Override
    @RequestMapping(
        value = {"/{id}/delete"},
        method = {RequestMethod.POST}
    )
    public String removeEntity(HttpServletRequest request, HttpServletResponse response, Model model, Map<String, String> pathVars, String id, EntityForm entityForm, BindingResult result, RedirectAttributes ra) throws Exception {

        LOGGER.info("wywołanie nadpisane metody: " + NewOrderController.class.toString());
        return "String";
    }

}

Upvotes: 1

Related Questions