My project makes use of Spring Tiles nad I need to implement a plain jsp approach, so the project has a page that makes use of tiles and I want to incorporate a iframe that loads html so that I can refresh as needed. I thin I found my solution to implement the resolver to load an html file.
I have a consern about resolver conflicts. Has anyone combined a number of viewresolers in their app?
You can define multiple view revolvers in your spring configuration file and set an order to them.
<bean id="viewResolverTiles"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.tiles2.TilesView</value>
</property>
<property name="order" value="1" />
</bean>
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
<property name="order" value="2"/>
</bean>
Note how we defined order property in both the view resolvers. Thus by default the Tiles based view resolver will be invoked. If Spring doesn't find view in that it moves to JSP view resolver.
Documentation: 16.5 Resolving views
I hope this helps.
Related
I have problem integrating my spring with quartz.
I have class UserService which has methods delegated to another class, which changes data in database.
I have added maven dependency for quartz and others needed, in my mvc-context I have declared bean
<bean id="quartzjob" class="example.UserService"/>
Then the factory bean
<bean id="runJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="quartzjob" />
<property name="targetMethod" value="testQuartz" />
And finally trigger
<bean id="Trigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="runJob" />
<property name="startDelay" value="1000"/>
<property name="repeatInterval" value="5000"/>
What my test method does, it delegates method to another class in which one record from database should be updated (This method works fine, because I'm using it already) however after that 5 seconds record is not updated, seems that something is wrong with quartz because methods were tested. Any ideas?
You also need to wire in your trigger to the quartz scheduler. Add this to your spring config.
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="Trigger" />
</list>
</property>
</bean>
I've a jspx file (for example test.jspx) in folder WEB-INF/templates and i want to access it by javascript.
I haven't a controller that returns that view, and in my application I'm using TilesViewResolver.
In test.jspx i want to use spring taglib to access message-bundle.
How i can configure spring to serve test.jspx ?
I'm using:
<mvc:view-controller path="/templates/test.html" view-name="test" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/templates/</value>
</property>
<property name="suffix">
<value>.jspx</value>
</property>
<property name="order" value="1" />
</bean>
It doesn't works.
I don't know if it's possible without any controller, but you can use a controller already provided by Spring MVC: ParameterizableViewController. Just provide the name of your jsp as the viewName property.
I am on a project using Spring 3.x MVC, and have implemented our controllers using annotations. We recently have a requirement to implement HandlerInterceptors, to which I have had some problems. When I specify in my configuration (dispatcher-sevlet.xml), the interceptor
<bean id="myInterceptor" class="com.myProject.controllers.MyInterceptor" />
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<list><ref bean="myInterceptor"/></list>
</property>
</bean>
then all is well, that is, any URL matches hits the myInterceptor code. When I try to add
<property name="mappings">
<props>
<prop key="/addFile.request">myFileController
</prop>
</props>
</property>
then I never hit the myInterceptor code...I have also tried to implement the above mapping code using #RequestMapping annotations.
It's easier to use the <mvc:interceptors> tag to configure interceptors if you're using annotation-based configuration.
E.g
<mvc:interceptors>
<!-- This runs for all mappings -->
<bean class="my.package.GlobalInterceptor"/>
<mvc:interceptor>
<!-- This one only runs for a specific URL pattern -->
<mvc:mapping path="/admin/*"/>
<bean class="my.package.AdminInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
Is it possible to have multiple resource bundles in spring mvc?
I want to separate my resource bundles for example one for errors, another for global messages, other for image names etc. so I don't have just one very big file
I'm using this
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
But here i can just specify 1 resource, can I use more?
You can just pass in a list using the setBasenames() method like this:
<beans>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>images</value>
<value>errors</value>
<value>globalMsgs</value>
</list>
</property>
</bean>
</beans>
Hi im wondering would it be possible to create global interceptor and set locale there.
I have urlrewrite rules to rewrite /fr/* to /*?siteLang=fr
I see examples how to set locale based on parameter but they all are the same and require me to use url mappings. Is it possible to do it globally so that locale interceptor gets called on each request no matter what controller is it for?
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="siteLang"/>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor"/>
</list>
</property>
<property name="mappings">
<value>
/*=dispatchController
</value>
</property>
</bean>
There is no such thing as dispatchController in my xml so i cant use it but idea would be to intercept everything (in whatever way).
i would basically like to have urls with locale at the beginning of uri followed by the application bit like
/fr/user/details
/de/products/hifi
etc
different controllers using the same convention of rewriting url and never using siteLang for controller specific reasons.
Thanks
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>
</mvc:interceptors>