Announcement Announcement Module
Collapse
No announcement yet.
Multiple pages using one controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple pages using one controller

    Hi everyone,

    This is kind of a stupid question but i can't seem to find an answer for it. I'm also not sure if this question has been asked but i did a pretty good search and came up with nothing.

    I was wondering if you can use 1 controller to view many pages?

    I have a libraryController (implements Controller) that gives basically gives you a list of books

    Code:
    public ModelAndView handleRequest(HttpServletRequest request,
                HttpServletResponse response) throws Exception {
    
            if (log.isDebugEnabled()) {
                log.debug("entering 'handleRequest' method...");
            }
    
            return new ModelAndView("admin/library", referenceData(request,null,null));

    but I need this same controller for another page "admin/editLibrary", "public/publicLibrary" and a few others. Instead of copying and creating the exact same controller with different beans to declare and urlMapping in the servlet i was wondering if i can just use this same controller.

    like having:
    -LibraryController
    -EditLibraryController
    -PublicLibraryController
    all being the same thing except for the last return part being different at the view.

    and then in the servlet having:
    Code:
    <bean id="libraryController" class="org.library.controller.LibraryController">
        	<property name="bookManager"><ref bean="bookManager" /></property>
    </bean>
        
    <bean id="editLibraryController" class="org.library.controller.EditLibraryController">
        	<property name="bookManager"><ref bean="bookManager" /></property>
    </bean>
    
    <bean id="publicLibraryController" class="org.library.controller.PulblicLibraryController">
        	<property name="bookManager"><ref bean="bookManager" /></property>
    </bean>

    I just need to display some data for those pages. Is there a general way with all Controllers (simpleFormController).

    Thanks a lot for all the help. This forum ROCKS!![/code]

  • #2
    In this case, I would probably create a Controller implementation where the view was configurable using DI. Then I would use parent/child beans to share the common configuration in the XML and just change the view name for each controller configuration.

    Rob

    Comment


    • #3
      Originally posted by robh
      In this case, I would probably create a Controller implementation where the view was configurable using DI. Then I would use parent/child beans to share the common configuration in the XML and just change the view name for each controller configuration.

      Rob


      I understand the part about configuring the XML file but what do you mean by DI?

      Comment


      • #4
        Dependency Injection.

        Comment


        • #5
          Can you explain

          Originally posted by PeaceOut
          I understand the part about configuring the XML file but what do you mean by DI?
          Can you explain me how will you do the inheritance with DI?

          Comment


          • #6
            Originally posted by raj_skromis
            Can you explain me how will you do the inheritance with DI?
            Like this:

            Code:
             <!-- Parent base DAO implementation - other DAOs will inherit -->
                <bean id="baseDAO" class="com.props.dao.BaseDAOImpl">
                    <property name="dataSource">
                        <ref bean="DefaultDataSourceName"/>
                    </property>
                    <property name="baseDataClassName">
                        <value>com.props.data.BaseData</value>
                    </property>
                </bean>
            
                <!-- Parent Generic DAO implementation - other DAOs will inherit -->
                <bean id="genericDAO" class="com.props.dao.GenericDAOImpl" parent="baseDAO">
                    <property name="tableName">
                        <value>LinenFabricStyle</value>
                    </property>
                </bean>
            
                <bean id="cachedDAO" class="com.partyrentalltd.props.dao.CachedDAOImpl" parent="genericDAO"/>
            
                <!-- DAO implementation for LinenOrderItem table -->
                <bean id="linenOrderItemDAO" parent="genericDAO">
                    <property name="tableName">
                        <value>LinenOrderItem</value>
                    </property>
                </bean>

            Comment

            Working...
            X