Results 1 to 6 of 6

Thread: Multiple pages using one controller

  1. #1
    Join Date
    Jul 2005
    Posts
    12

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    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
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

  3. #3
    Join Date
    Jul 2005
    Posts
    12

    Default

    Quote 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?

  4. #4

    Default

    Dependency Injection.

  5. #5
    Join Date
    Dec 2005
    Posts
    7

    Default Can you explain

    Quote 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?

  6. #6
    Join Date
    Jun 2006
    Posts
    2

    Default

    Quote 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>

Similar Threads

  1. Replies: 8
    Last Post: Oct 30th, 2012, 11:33 AM
  2. Replies: 6
    Last Post: Sep 1st, 2005, 09:18 AM
  3. Multiple views and pages question
    By jwray in forum Swing
    Replies: 3
    Last Post: Feb 19th, 2005, 09:22 AM
  4. Multiple Pages
    By afida in forum Swing
    Replies: 12
    Last Post: Feb 16th, 2005, 08:42 AM
  5. Replies: 2
    Last Post: Sep 14th, 2004, 09:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •