Page 1 of 1

Extending Admin3 Controllers

Posted: Fri Aug 09, 2013 11:47 am
by tduffey
What is the recommended way to extend controllers in admin3? For example, I'd like to override AdminOrderController but because it already defines a @RequestMapping for "/order" I will end up with a startup error due to ambiguous URL mappings. Is there a convenient way to deal with this without having to fork broadleaf-admin-module?

Re: Extending Admin3 Controllers

Posted: Tue Oct 08, 2013 8:42 pm
by liweinan0423
I think you can define a new controller bean in the applicationContext.xml file and use <alias> tag to replace the original bean with your newly defined controller bean.
For example:

Code: Select all

<alias name="myAdminOrderController" alias="blAdminOrderController" />
<bean id="myAdminOrderController" class="you.order.controller">
</bean>

Re: Extending Admin3 Controllers

Posted: Tue Oct 08, 2013 8:49 pm
by tduffey
Cool, I will give that a try. I wonder if long term the admin tool should follow the same pattern as the demo site and provide some base controllers that do not get mapped to requests for easier customization.

-t

Re: Extending Admin3 Controllers

Posted: Thu Oct 10, 2013 3:36 pm
by phillipuniverse
No, the admin tool will keep @RequestMapping in the framework. The idea is that you can get 90% of your functionality from what's already there without a huge need to customize. Contrast that with the frontend where it is extremely likely that users will throw away the controllers that we built for their customized frontend UI.

The correct solution is as llweinan0423 mentioned, override the bean ID in the controller. However, you don't need to specify an alias at all. Broadleaf will override bean IDs by default, so this syntax is perfectly safe:

Code: Select all

<bean id="blAdminOrderController" class="your.admin.order.controller" />