3 Replies Latest reply on May 6, 2008 3:27 PM by Rend D

    urls in resource messages

    Andrew A Newbie

      First, I wasn't really paying attention and ended up posting this on the Wiki Forum, so apologies for duplication.  It wasn't intentional.

      What is the best way to inject url's into messages from resource files?

      I have looked around and have not been able to find a solution that is wholly satisfactory to me.  The best I have come up with is something similar to the following:

      <h:outputFormat value="#{messages['registration.joiningConditions']}" escape="false">
          <f:param value="&lt;a href='/tnc.seam'&gt;#{messages['registration.tnc']}&lt;/a&gt;"/>
          <f:param value="&lt;a href='/privacy.seam'&gt;#{messages['registration.privacy']}&lt;/a&gt;"/>

      with a resource entry something like:

      registration.joiningConditions=blah blah {0} blah blah {1} blah
      registration.tnc=Terms and Conditions
      registration.privacy=Privacy Policy

      Doing the following definitely doesn't feel right embedding a conversation id into a static link, but feel free to correct me if that is what I should be doing:

      <f:param value="&lt;a href='/todo.seam?cid=#{conversation.getId()}'&gt; ...

      I feel like I may be missing something really obvious and that a better solution should exist, but I have not been able to figure one out.  Any suggestions?  Or confirmation that this is the correct way of approaching this?



        • 1. Re: urls in resource messages
          Stefan Schubert Newbie

          There are still some problems I am having with your solution. First you might want to create the link with Seam in order to keep it manageable by Seam like this:

          <s:link view="..."/>

          So wouldn't it be better to evaluate the link expression in the f:param value body? I'm not an expert with JSF, but I'm just trying to become one. So I would be very curious on this solution as it would answer two of my current questions ;-)

          Second it seams not very desireable to define a link in a message into the view as the message might be displayable in many views. Else you could put it into a template but this as well seems very dirty. Is there a convenient and clean solution for such a common problem?

          Kind regards

          • 2. Re: urls in resource messages
            Andrew A Newbie

            Thanks for the feedback Stefan.

            The s:link will append the conversation id, like I did using conversation.getId() to the url which I said I felt uncomfortable with, but you cannot use a child node inside an attribute, so you cannot use s:link as part of a f:param.  From what I understand of parameters, the body content of the f:param tag must be empty, so you cannot place the s:link in the f:param body, which would be a great solution if allowed.

            Additionally, it is not suitable to break the resource sentence up and concatenate it together again with the links between the sentence fragments, as different languages will have different grammatical rules that will not make sense with such an approach, even perhaps requiring the order of the links to be presented differently.

            The other angle I briefly toyed with was rather than using {0} place holders and f:param injection as per the above, I considered perhaps using inline #{} EL parsing as per the Seam documentation resource examples.  But you are still faced with how to construct a url within the EL tag.  Calling a backing been that artificially creates the url string is no better than the other solution, arguably slightly worse, and again, you cannot insert a s:link inside a #{} EL directive and expect it to be resolved.

            I would envisage that this would be a relatively common use case for internationalising text, but I do not see a clean way to resolve it. As you can see, I have problems with this solution as well, hence posting it on the forum to see if other people had alternative solutions that were perhaps a little cleaner.

            On to your last point, if I'm understanding you correctly...  Even if you are using a template and it is a common piece of text, used in a number of views, the text of that template still should be taken from a resource file.  It would be worse to create a different page (template or otherwise) per supported language, unless your web site was text heavy, such as a wiki.  And the original concept of the web (as per Tim Berners-Lee's vision), was to have text with meaningful hyperlinks embedded in that text at appropriate locations.  So some places in a web site are bound to have text that you want to internationalise and some words in the text that you want to link to other pages on your own site or externally.  So I'm not sure what the issue is that you see as it not being desirable to embed hyperlinks into a message?

            But regardless, the question remains, are there better or preferred solutions for this issue that differ from mine?  Or even is what I have come up with an acceptable approach?  Assuming that I really do want to embed hyperlinks into some message strings.



            • 3. Re: urls in resource messages
              Rend D Newbie

              I've not found a better solution to this problem. I'd also appreciate any insights.