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 resourc开发者_运维问答e bundle or build a switch to either terms_en.xhtml and so on.
Whats the best/default way to handle long texts in JSF?
Typically there are two approaches:
- 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.
- 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.
精彩评论