2 Replies Latest reply on Nov 22, 2007 4:17 AM by Kurt Edegger

    formattedText with dynamic content - escaping

    Kurt Edegger Newbie

      Hi!

      I'm facing the situation, where I do have a page containing a formattedText tag to display some information, I'm getting from the resource bundle as shown below:

      <s:formattedText value="#{messages['newGroupCreated.text']}"/>
      


      whereas the text in the message bundle is:
      newGroupCreated.text=The new group '*#{group.name} (#{group.nameShort})*' was created successfully.
      


      Nothing special - everything is working fine until one of the dynamic contents ("group.name" or group.nameShort") is containing a special character(e.g.: '*', '/', '~',...), which needs to be escaped to be displayed correctly.

      My question would be, how to deal with the situation?
      Is there a Seam class available doing the escaping work or do I manually have to look for occurrences of org.jboss.seam.text.SeamTextParserTokenTypes in the dynamic content?

      Any pointers?

      Best regards, Kurt


        • 1. Re: formattedText with dynamic content - escaping
          Pete Muir Master

          No, we have no built in class for doing this, but it could be an interesting addition for SeamText, so it would be interesting to see what you come up with.

          • 2. Re: formattedText with dynamic content - escaping
            Kurt Edegger Newbie

            Hi Pete,

            thank you for showing interest.
            I gave the whole situation a brief thought and came to the conclusion that a generic approach that transparently escapes rich text tokens in s:formattedText would be hard to implement, because the method would have to differentiate somehow between formatting rich text tokens and tokens that are simply in the text as characters, so I'm using a pretty simple, but working, approach right now.

            I'm having a Seam managed Java Bean called "ste" (short for seam text escaper), which offers a method "esc(String s)" that escapes the rich text tokens using a Stringtokenizer.
            So in the message bundle I can escape certain properties, that could contain rich text tokens which needs to be escaped like that:

            newGroupCreated.text=The new group '*#{ste.esc(group.name)} (#{ste.esc(group.nameShort)})*' was created successfully.
            


            Now 'newGroupCreatet.text' can be used in <s:formattedText /> even if 'group.name' contains characters like underscore or slash without breaking the generated HTML.

            If anyone is interested, I can post the code as well, but it's nothing spectacular.

            Best regards,

            Kurt