4

in most cases i just have a lot of short text strings combined somewhere in the page. But on a few occasions i have just a page with long static text, like terms or faq.

Now, just put the paragraph also in the resource bundle or build a switch to either terms_en.xhtml and so on.

Whats the best/default way to handle long texts in JSF?

webstrap
  • 1,004
  • 1
  • 10
  • 24

1 Answers1

2

Typically there are two approaches:

  1. Put the text no matter how long into resource files. I believe you do not want to do that for it is cumbersome and resource files become harder to maintain.
  2. Create static files (i.e. HTML pages or simple text files) and load them at runtime. In case of HTML files, you can easily embed them with for example iframe. All you need is to read correct file but the name could be built by backend controller based on UIViewRoot Locale. With static text files, your approach would be different: simply load them on demand on the backend side and ask for the contents.

Personally, I prefer second approach with simple text files. If you do not need any "rich" features like different styles for given word or paragraph, it could be very easy to implement. In fact iframe way is also very easy to handle, the only reason I don't buy this idea is this iframe thing which means two requests instead of just one.

BTW. Actually you could load HTML on the backend side and display that correctly but you have to remember not to escape the tags:

<h:outputText escape="false" value="#{someController.faq}" />

Be sure this is not something that could be entered by end user as you would end up with XSS vulnerability.

Paweł Dyda
  • 18,366
  • 7
  • 57
  • 79
  • I am not sure if JBoss Seam sets UIViewRoot's Locale (it should), the answer is JSF specific, just like the question. – Paweł Dyda Jun 21 '11 at 10:07
  • I use the Seam LocaleSelector to access the locale, that sets the UIViewRoot's locale too i think. - Another way could be, add the long texts in the .xhtml file and surround it with rendered= depending on the language or includes of the different *_xx.xhtml files depending on that. – webstrap Jun 22 '11 at 14:06
  • Yes, conditional rendering is one of possible solutions. The only problem I see about it, it is hardly maintainable. How to add more languages? How to modify existing ones? Of course it is possible but troublesome. – Paweł Dyda Jun 22 '11 at 14:27
  • cross reference http://stackoverflow.com/questions/6497886/correct-way-to-do-internationalization-in-jsf-for-full-html-pages – webstrap Jun 28 '11 at 17:40