Announcement Announcement Module
Collapse
No announcement yet.
Any Controller called more than once Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Any Controller called more than once

    Hi,

    I have added the following to my config.

    <bean id="messageSource" class="org.springframework.context.support.Resourc eBundleMessageSource">
    <property name="basename">
    <value>messages</value>
    </property>
    </bean>

    Now all my controllers get called twice. Any ideas.

    THanks

    G

  • #2
    Problem found - but not solved

    I have found the issue to my problem.

    It seems when you use the spring tab <spring:message code="bla.bla>

    it creates two requests to the same controller. Don;t know why but it does.

    I have got around this by creating my own message tag.

    Code Message tag

    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:fn="http://java.sun.com/jsp/jstl/functions">

    <jsp:directive.attribute name="key" required="true"/>
    <jsp:directive.attribute name="escapeXml" type="java.lang.Boolean"/>

    <c:set target="${messageResolver}" property="key" value="${key}"/>

    <c:set var="message" value="${messageResolver.messageForKey}"/>

    <c:choose>
    <c:when test="${escapeXml}">
    ${fn:escapeXml(message)}
    </c:when>
    <c:otherwise>
    ${message}
    </c:otherwise>
    </c:choose>
    </jsp:root>

    And a class which resolves the message

    Code ResourceBundleResolver

    public class ResourceBundleResolver implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    private String key;
    /**
    * Gets a message from the properties file
    * @return
    */
    public String getMessageForKey()
    {
    Locale locale = new Locale("en", "GB");
    return applicationContext.getMessage(getKey(), new Object[0], "No Key Value", locale);
    }

    public String getKey() {
    return key;
    }

    public void setKey(String key) {
    this.key = key;
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.applicationContext = applicationContext;
    }
    }


    And the following entries in my spring-servlet.xml

    <bean id="messageSource" class="org.springframework.context.support.Resourc eBundleMessageSource">
    <property name="basename">
    <value>messages</value>
    </property>
    </bean>

    <!--This gets injected into the class that to add it to the request session space -->
    <bean id="messageResolver" class="com.alito.util.ResourceBundleResolver" />

    I don;t know if this is a bug ??

    cheers

    G

    Comment

    Working...
    X