Announcement Announcement Module
No announcement yet.
EL support in MessageTag/ThemeTag Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • EL support in MessageTag/ThemeTag

    Hi All,
    I have recently had a requirement to add EL support to a theme properties file. i.e. after a theme tag has retrieved the message from the property file, the actual message contains EL that needs evaluating.

    Code: extract:
    city.title=Go exploring in ${city} for sun and fun.
    to enable this I made a one line addition to org.springframework.web.servlet.tags.MessageTag (At ln171 - Spring 1.2.1)
    msg = ExpressionEvaluationUtils.evaluateString("msg", this.msg, pageContext);
    Firstly does anyone have a use for this? Secondly how does one go about getting this added to the spring codebase (obviously based on that it's correct and that its useful for other people)


  • #2
    Personally I do not see any benefits for this over the normal formal parameter replacement used by the standard message format parameter replacement. The only difference is that it would not be required to pass in parameteres to be replaced. However, if the EL tag changes for some reason, say refactoring for common naming changes) it will not be evaluated and your message will not display properly.

    That said, Spring has a lot of ways to do some things and this could just be an option to use when setting up a message source in the context, choice is always a good thing


    • #3

      Are we talking about the same thing? My EL is located in the property file, not in a jsp file. Perhaps there is a spring way of doing this, but I couldn't find it in the docs.

      At the moment my jsp file has the following:
      <spring:theme code="city.departure.css"/>
      and the file has:
      How would you do it with the "standard message format parameter replacement"?



      • #4
        Propery place holders are in the form "This is number {0} of {1} posts for the subject {2}"

        therefor when you want to print the message you would have in your properties file.

        my.message=This is number {0} of {1} posts for the subject {2}

        When the message is extracted from the properties file you need to pass parameters to replace the property holders i.e.

        <spring:message code="my.message" arguments="${current_num},${total_num},${subject}"/>

        The arguments passed here to replace the place holders can be EL Expressions as in this case or actual values. The are comma seperated for and their placement correspond to the numbers in the message.

        In your case what you would end up with is something like:

        my.message=This is number ${current_num} of ${total_num} posts for the subject ${subject}

        And the call would be <spring:message code="my.message"/> No need for arguments to be sent to replace the property holders as the message already contains the EL Expressions

        The actual code you need for the theme tag is without your code change is:

        <spring:theme code="city.departure.css" arguments="${departures}"/> with the entry in the properties file is


        This amounts to the same thing but without having to modify the Spring Code



        • #5
          AH I see!

          Thanks, thats great. I didnt find that in the docs at all.