Question marks instead of Unicode characters with resource bundle in view - jsf

I use Primefaces 3.5 + Lifaray 6.2.
I need some internalization in my app.
I use Language_en_US.properties file and others for string resources.
In backbean I use ResourceBundle.getBundle and it's working propertly.
But in view I use
<p:outputLabel value="#{i18n['server-address']}"/>
And with Cyrillic i always got question marks on page
?????? ??????
It's in page code already as question marks, so it's not a browser problem.
If I use ResourceBundle.getBundle directly
<p:outputLabel value="#{adminBean.getString('main')}"/>
then I got Cyrillic.
Is there any way to use i18n without bean?

Liferay expects the resource bundles to be encoded in UTF-8 (unlike PropertyResourceBundle in plain Java, which uses ISO-8859-1).
Check encoding of you Language_ru_RU.properties file - most likely it is not UTF-8. That would explain that ResourceBundle.getBundle works correctly, while #{i18n['server-address']} doesn't.
While it's a deviation from the standard, UTF-8 encoding is quite comfortable, as there's no need for character escaping.
See Localizing JSF Portlets in Liferay documentation.

Related

What is the equivalent tag for ScriptCollector?

We want to migrate our project from IBM WebSphere 6.1 to Tomcat 6, but in our JSP-JSF UI pages we have extensively used below IBM JSF tags.
ScriptCollector
PanelRowCaregory
PagerWeb
OutPutSelections
InputRowSelect
InputHelperDatePicker
InputHelperAssist
ConvertMask
And to replace above tags, we are trying to find the equivalent tags from Sun JSF or any other open source libraries, but we didn't find any equivalent tags.
I wanted to know whether any body has already worked on this kind of migration project, if yes can you please share the equivalent tags?
or if you solved it differently even that info also will be useful.
Thanks in Advance.
There's no standard JSF equivalent for the <hx:scriptCollector> (although the JSF 2.0 <h:head> comes close). The <hx:scriptCollector> is only required by those IBM-specific <hx:xxx> components. It's designed to collect all JavaScript files required by those <hx:xxx> components and then render the desired <script> tag(s) without potential duplicates when multiple components require the same JS files. It's not required by any standard JSF component.
In other words, just get rid of it without replacement.
As to other tags, just check the available standard components in tag documentation or Java EE tutorial. If none is available, just pick a component library like PrimeFaces or RichFaces. If you still can't figure out, ask an individual question for the particular tag.

Practical implications of Facelets ui:remove tag

I want to understand the basic mechanism of <ui:remove>. As per my knowledge, <ui:remove> is basically used in conjunction when basic HTML stuff is part of your Facelets page. When you want, when rendering of the Facelets page happen, it should ignore this part of HTML code, we can use the <ui:remove> tag.
Still I am confused about practical implications of <ui:remove>. How often we need to use this Facelets tag? Additionally, the Facelets page is not compiled everytime when the page is hit.
It's useful to remove content which is required during design time, but not during run time, such as comments, some stubbed content (e.g. "lorem ipsum") which aids in filling up the page content to fit the layout in visual designers such as Dreamweaver, etc.
If you're not a page designer, but already retrieve designs as PSD/AI/etc, it's indeed useless to you.
See also:
Is there a way to run a JSF page without building the whole project?
Outcommented Facelets code still invokes EL expressions like #{bean.action()} and causes javax.el.PropertyNotFoundException on #{bean.action}
JSF display HTML comment

Set request character encoding of JSF input submitted values to UTF-8 in GlassFish

I have a problem with the values inserted in all my <h:inputText> fields. Some characters are not encoded in the right way. E.g. if I put ciò in the input field I get ciò.
How can I allow a user to insert text with those characters and save them correctly? The problem in not in the DB encoding since I already have the wrong value before inserting it in the DB.
I'm using JSF 2 with Facelets and GlassFish as application server.
You need to tell Glassfish to use UTF-8 to decode paramters instead of (default) ISO 8859-1. Add the following entry to the <glassfish-web-app> of your /WEB-INF/glassfish-web.xml file:
<parameter-encoding default-charset="UTF-8" />

Problem with outputlink on files

I'm working on a JSF 2.0 project using Mojarra, PrimeFaces and Tomcat 6.x.
I created some outputlink that point to files. These files are external of my WAR in a directory under Apache HTTPD's control.
<h:outputLink value="#{fileItem.linkTarget.sourceUrl}">#{fileItem.boname} (#{fileItem.linkTarget.mediaType})</h:outputLink>
The sourceUrl is value like /dir/subDir/file.pdf. When my sourceUrl doesn't contains space it's work. But when its contains space, they are are replace by +.
/dir/subDir/big file.pdf become /dir/subDir/big+file.pdf. When i replace the + with space in a normal webbrowser, it's work?
What's wrong and how can I fix it?
I get the same problem with graphicImage of mojarra and i solve by using Primefaces's graphicImage.
In general I would not recommend to use blank spaces in urls.
If you have no influence on the file names in the url's you should url-encode these names as described here URL-Encoding. The blank space has to be replaced by %20. Maybe there is a java class that does the encoding for you. I only know it from PHP, there you have a function like urlEncode().

Facelet does not convert formatted currency correctly

I have the follwing code inside a facelet page:
<h:inputNumber value="bean.property">
<f:convertNumber type="currency" />
</h:inputNumber
The converter is because there can be a kind of default value inside the input field, which comes from the bean property. Everything is rendered correctly. The value inside the input field is rendered with an "€" character (e.g. "1.453 €".
When I submit the form there comes an error up:
"nameOfInputField" konnte nicht als ein Geldbetrag erkannt werden '304,00 â¬'
In english it is some like:
"nameOfInputField" could not be regognized as an amount of money '304,00 â¬'
Please have a look at the "€" character. It seems to be printed as "â¬". While it was rendered correctly before submitting the form, now it looks like "â¬" inside the error message and inside the input field.
All pages are encoded in UTF-8.
What is the reason for this error?
How can fix it?
Thanks in advance
â¬
This is typical for the € from an original UTF-8 source which is incorrectly been decoded using ISO-8859-1. Here's a small snippet which demonstrates that:
System.out.println(new String("€".getBytes("UTF-8"), "ISO-8859-1"));
All pages are encoded in UTF-8.
You're likely talking about response encoding. You need to set the request encoding as well.
To set the encoding for GET requests (basically: URI encoding), you need to consult the appserver specific documentation. As it's unclear which one you're using, here's a Tomcat targeted example: <Connector URIEncoding="UTF-8" />. To set the encoding for POST requests, you need to create a simple filter which does request.setCharacterEncoding("UTF-8") if it is null. More background information and hints can be found in this article.
Put this ontop of your facelets page:
<?xml version="1.0" encoding="UTF-8" ?>
It will instruct the facelets parser.

Resources