Results 1 to 2 of 2

Thread: Initialize bean that has HashMap

  1. #1
    Join Date
    Feb 2011
    Posts
    2

    Default Initialize bean that has HashMap

    I asked the same question in web forum but was answered..so asking it seems like the right forum.

    How to I initialize the PageMappingBean in spring-mvc.xml or something ? I am doing something similar to viewResolver but I have single controller that serves all pages so the plain view resolver is not very useful for me.

    Class PageMappingsBean {
    HashMap<String,PageMapping> pageMap = new HashMap<String,PageMapping>();
    //getter and setters
    }

    Class PageMapping {
    String TemplateName;
    String ContentName;
    bool isSecure;
    //getter and setters
    }

  2. #2
    Join Date
    Dec 2010
    Location
    Singapore
    Posts
    287

    Default

    How to I initialize the PageMappingBean in spring-mvc.xml or something ?
    By initialize do you mean populating the pageMap? If so, It would be something like,

    Code:
    	<bean id="pageMappingsBean" class="com.web.PageMappingsBean ">
    		<property name="pageMap" ref="pageMap" />
    	</bean>
    
    	<util:map id="pageMap" map-class="java.util.HashMap">
    		<entry key="page1" value-ref="page1" />
    		<entry key="page2" value-ref="page2" />
    	</util:map>
    
    	<bean id="page1" class="PageMapping ">
    		<property name="TemplateName" value="blabla"/>
    		<property name="ContentName" value="blabla"/>
    		<property name="isSecure" value="true"/>
    	</bean>
    	
    	<bean id="page2" class="PageMapping ">
    		<property name="TemplateName" value="blabla"/>
    		<property name="ContentName" value="blabla"/>
    		<property name="isSecure" value="true"/>
    	</bean>
    I have single controller that serves all pages so the plain view resolver is not very useful for me.
    How one controller serving all the requests or multiple controller serving request makes any difference when it comes to the view resolver?
    Amila Domingo

Tags for this Thread

Posting Permissions

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