Okay maybe I wasn't clear enough....
Alright lets say there is for example a dropdown box that lists 3 options,
and this box appears on more than one page in the application and placed
their by a templating mechanism like tiles.
> ___________ _____________
> | dropdown1 | | dropdown2 |
> | item1 | | item1 |
> | item2 | | item2 |
> | item3 | | item3 |
> |__________ | |____________ |
> page 1 page 2
>
>
Now let's say that both of the pages (above) are loaded up by a subclass of
the SpringMVC Controller (TilesComponentParentController) which stores a
list of "subController's" that are defined by the
(iTilesDisplayComponentController) interface, thus we have:
> (implements Controller) (interface)
> ________________________________
> ____________________________________________
> | TilesComponentParentController | |
> iTilesDisplayComponentController |
> |-------------------------------------------------| |
> --------------------------------------------------------------- |
> | tilesComponentControllers : ArrayList | |
> populateDisplayComponentController(ModelAndView mav)|
> | ^(iTilesDisplayComponentControllers) |
> _______________________________________________
> |-------------------------------------------------|
>
> | handleRequest(req, resp) |
>
> |________________________________|
>
>
When handleRequest() is called in the subclass of
TilesComponentParentController the list of classes that implement with in
the iTilesDisplayComponentController are called as follows:
subclass of TilesComponentParentController wrote:
>
> log.debug("TilesComponentParentController: Processing Tiles
> Display
> Controllers");
> Iterator i = tilesComponentControllers.iterator();
>
> while(i.hasNext())
> {
> iTilesDisplayComponentController tdcc =
> (iTilesDisplayComponentController) i.next();
> tdcc.populateDisplayComponentData(mav);
> }
>
And in the .populateDisplayComponentData(ModelAndView) method of a class
that implements iTilesDisplayComponentController the dropdown box is
poplated:
DropdownSubComponentController class which implements
iTilesDisplayComponentController wrote:
>
> public void populateDisplayComponentData(ModelAndView mav)
> {
> log.debug("DropdownBoxDisplayComponentController: Processing
> Display
> Component.");
>
> ArrayList dropdownItems = new ArrayList();
>
> dropdownItems.add(new String("item 1"));
> dropdownItems.add(new String("item 2"));
> dropdownItems.add(new String("item3"));
>
> mav.addObject("dropdown_names", dropdownItems);
> }
>
And than in our Spring IoC we have:
action-servlet.xml wrote:
>
> <beans>
> ...
> <!-- This is a subclass of TilesComponentParentController -->
> <bean id="page1Controller"
> class="com.mooo.mv.webapp.action.PageOneController">
>
> <property name="tilesComponentControllers">
> <list>
> <!-- Populates the dropdown box -->
> <ref
> local="sub_header_tiles_display_controller"/>
> </list>
> </property>
> </bean>
>
> <!-- This is a subclass of TilesComponentParentController -->
> <bean id="page2Controller"
> class="com.mooo.mv.webapp.action.PageTwoController">
>
> <property name="tilesComponentControllers">
> <list>
> <!-- Populates the dropdown box -->
> <ref
> local="sub_header_tiles_display_controller"/>
> </list>
> </property>
> </bean>
>
> <!-- Implements the iTilesDisplayComponentController -->
> <bean id="sub_header_tiles_display_controller"
> class="com.mooo.mv.webapp.action.displaycomponentcontroller.DropdownSubComponentController">
>
> </bean>
> ...
> </beans>
>
This way since both datasources for the dropdown box component on both pages
are the same, we can just add the subController
(iTilesDisplayComponentController) which populates that component for the
dropdown on both page 1 and page 2. And if the code changes for either we
only have to change it in the one place. It seems like a good idea to me
but I'm not sure if it is actually thread-safe to do since I don't know much
about multi-threading and such things in SpringMVC.
maskkkk wrote:
>
> Hello,
>
> I have an idea and I have a sneaky suppision that it's wrong so I'm going
> to post it here and see if there's anything wrong with it.
>
> On the front-end I have several display components that are used over and
> over again on several pages of my app.
>
> Individually, each of these display components require their own unique
> data to be loaded into the Request, Response or ModelAndView .
>
> That being said, assuming that more than one of the page share the same
> display component: Is it okay to, have a Collection of "display component
> controllers" which populate the Request, Response, and ModelAndView with
> the data needed for each component inside of a parent Controller? (set by
> the IoC container of course)
>
> To me what I mentioned above sounds like a portlet system. But it also
> seems to me that maybe SpringMVC might be flexible enough that you could
> just chain up a couple of Controllers together to do the same thing before
> displaying the view (that's why I have a suppision that what I am
> proposing might be wrong).
>
> Could someone please offer me some insight on this?
> (If what I wrote doesn't make any sense, please let me know, I've tried to
> be as clear as possible...)
>
> Thank you,
> Andrew J. Leer
>
>
>
--
View this message in context:
http://www.nabble.com/Question-on-SpringMVC-Controllers-tf2940262s2369.html#a8238664
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]