Announcement Announcement Module
Collapse
No announcement yet.
smarter MethodNameResolver Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • smarter MethodNameResolver

    At the moment I have to map all the url`s from the webpage to the applcation a few times:

    Code:
    <bean 	id="searchCommandController"
    			class="anchormen.schiphol.web.SearchCommandController">
    
    		<constructor-arg index="0">
    			<ref bean="searchService"/>
    		</constructor-arg>
    
    		<constructor-arg index="1">
    			<value>10</value>
    		</constructor-arg>
    
    		<property name="methodNameResolver">
    			<ref local="searchCommandControllerResolver"/>
    		</property>
    	</bean>
    
    	<bean 	id="searchCommandControllerResolver"
    			class="org.springframework.web.servlet.mvc.multiaction.MethodNameResolver">
    
    		<property name="mappings">
    			<props>
    				<prop key="/jumpPage.spring">jumpPageHandler</prop>
    				<prop key="/nextPage.spring">nextPageHandler</prop>
    				<prop key="/previousPage.spring">previousPageHandler</prop>
    				<prop key="/search.spring">searchHandler</prop>
    			</props>
    		</property>
    	</bean>
    
    	<bean 	id="urlMapping"
    			class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    
    		<property name="mappings">
    			<props>
    				<prop key="/jumpPage.spring">searchCommandController</prop>
    				<prop key="/nextPage.spring">searchCommandController</prop>
    				<prop key="/previousPage.spring">searchCommandController</prop>
    				<prop key="/search.spring">searchCommandController</prop>
    			</props>
    		</property>
    	</bean>
    This is boring and error prone. Could it be possible to add all url`s matching a specific pattern to a controller and let MethodResolver figure out which method to find?

    Code:
    <bean 	id="searchCommandController"
    			class="anchormen.schiphol.web.SearchCommandController">
    	
    		<property name="methodNameResolver">
    			<ref local="searchCommandControllerResolver"/>
    		</property>
    	</bean>
    
    	<bean 	id="searchCommandControllerResolver"
    			class="org.springframework.web.servlet.mvc.multiaction.ReflectionMethodNameResolver">
    	</bean>
    
    	<bean 	id="urlMapping"
    			class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    
    		<property name="mappings">
    			<props>
    				<prop key="/search.*.spring">searchCommandController</prop>
    			</props>
    		</property>
    	</bean>
    Something like this. Every 'method' name from a url is matched with a method on the controller without writing any glue/matching code.

  • #2
    Great, I have found: InternalPathMethodNameResolver

    it does the job

    Comment

    Working...
    X