Announcement Announcement Module
Collapse
No announcement yet.
String escaping in Grails GSP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • String escaping in Grails GSP

    Hello, I've come across a problem, I'm trying to pass in a regular expression to a taglib as a string, and I need to include some groups in the regex, which requires the [ and ] characters.

    However when I try to insert them in my gsp file, they are seen as starting a list or map and throw an error.

    I tried using ' instead of " and even slashy strings, but none worked.

    Heres an example of what I'm talking about:

    Code:
    <g:tag pattern="/[A-z]{2}/" />
    The [ starts a list and I can't seem to escape it which causes an error in the IDE and disallows building/running, I put a \ infront of it and nothing.
    Any suggestions?
    The IDE i'm using is IntelliJ IDEA 9 Ultimate.

  • #2
    It seems to work fine if you don't have the '/' characters in there.

    Comment


    • #3
      are you using an IDE or just the command line?

      Comment


      • #4
        I've come up with a few solutions to get the IDE to stop seeing it as an error.

        1: Inject it with Groovy using <%%> tags
        Ala:
        Code:
        <% def pattern = /patternhere/ %>
        <g:tag pattern="${pattern}"/>
        That works fine.

        2: Fake it out with an empty injection.
        Code:
        <g:tag pattern="${''}[A-z]{2}" />
        works fine too and doesn't error for some reason.

        I'm probably going with solution 2 for now, just to cut down on number of lines.
        Maybe IDEA 10 fixed this issue, at least it's not a GRAILS / GROOVY bug

        Comment

        Working...
        X