JSF displays code instead of translation - jsf

I'm new to JSF. Right now I am developing a JSF project. I have 2 properties files, configured correctly. (tested on previous Servlet/ JSP proj.)
The problem is when I try to get the value from the property file, I get just a code typed in my browser like this:
Welcome, "#{bundle.dude}"
But it should be like:
Welcome, dude
That's my problem.
My faces-config.xml:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.1"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd">
<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>en</supported-locale>
<supported-locale>ru</supported-locale>
</locale-config>
<resource-bundle>
<base-name>i18n.MediaPortal</base-name>
<var>bundle</var>
</resource-bundle>
</application>
</faces-config>
i18n property files are located at src/main/resources/i18n/ dir
Every answer is appreciated.
Thanks in advice.
Nazar

Related

Primefaces openDialogue not working

Prerequisites:
JSF 2.1
Primefaces 5.2
Glassfish 3.1
User Story:
When clicking on a CommandButton, a Window should pop up.
Implementation:
commandbutton
<p:commandButton value="+" actionListener="#{beanname.showDialogue}" />
bean
public void showDialogue() {
RequestContext.getCurrentInstance().openDialog("/Dialogues/Dialogue");}
faces-config
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
version="2.1">
<application>
<action-listener>org.primefaces.application.DialogActionListener</action-listener>
<navigation-handler>org.primefaces.application.DialogNavigationHandler</navigation-handler>
<view-handler>org.primefaces.application.DialogViewHandler</view-handler>
</application>
</faces-config>
The popup to open is placed in src/main/webapp/Dialogues
Outcome:
When Clicking on the button the URL reloads from host/applicationname/ to host/applicationname/faces/[pagewherecommandbuttonis]
Question:
What am i (possibly) missing here, in order to get the popup working?
You must do this:
org.primefaces.context.RequestContext.getCurrentInstance().execute("PF('widgetName').show();");

How to change the locale for one view in jsf?

there is a way to change the locale for especific view in jsf?
i can try the locale via faces-config.xml, but i just wanna a specific view.
faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<locale-config>
<default-locale>es</default-locale>
<supported-locale>ca</supported-locale>
<supported-locale>en</supported-locale>
</locale-config>
You can set the locale on a per-view basis by nesting your content in a <f:view> tag that has one of its attributes, locale, for exactly this purpose:
<f:view locale="#{localeBean.selectedlocale}">
For more information consult Localization in JSF, how to remember selected locale per session instead of per request/view.

JSF 2.1 - Facelet cache factory configuration

I am using Mojarra 2.1.2 and want to configure the facelet cache factory. I tried the following in my WEB-INF/faces-config.xml but it does not seem to work.
<factory>
<facelet_cache_factory>org.valuesource.custdb.web.extension.SimpleFaceletCacheFactory</facelet_cache_factory>
</factory>
You shouldn't use underscores. Use hyphens.
<facelet-cache-factory>
No one XML element of faces-config.xml uses underscores. Note that the FaceletCacheFactory was introduced in JSF 2.1, so ensure that your faces-config.xml root declaration conforms JSF 2.1:
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
version="2.1">

JSF define custom namespace for component declaration

when you use a component from extarnal libraries (or custom component) in JSF page you add the xmlns declaration, for example:
xmlns:util="http://java.sun.com/jsf/composite/component/util
I would like to know what I have to do to use a private address in the Namaspace like this below:
xmlns:p="http://primefaces.prime.com.tr/ui"
It is something related to packages? Or it depends from the name of the .JAR that contains the components?
Thank you!
For Facelets this is definied in .taglib.xml file. In case of PrimeFaces it's /META-INF/primefaces-p.taglib.xml:
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
version="2.0">
<namespace>http://primefaces.prime.com.tr/ui</namespace>
...
Note the <namespace>. For JSP this is definied in the .tld file, for PrimeFaces it's the /META-INF/primefaces-p.tld
<?xml version="1.0" encoding="UTF-8"?>
<taglib xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1">
<tlib-version>1.2</tlib-version>
<short-name>p</short-name>
<uri>http://primefaces.prime.com.tr/ui</uri>
...
Note the <uri>.

JSF tags not being rendered as HTML [duplicate]

This question already has an answer here:
JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output
(1 answer)
Closed 6 years ago.
I'm following the Java EE firstcup tutorial using Netbeans and Glassfish.
When I execute the JSF web tier I've been instructed to code, the browser gets the same JSF markup coded in the .xhtml file, and the tags are not rendered as HTML tags. I know this by using the view source code in my browser.
For example, for this code:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Page title here</title>
</h:head>
<h:body>
<h2>
<h:outputText value="#{bundle.WelcomeMessage}" />
</h2>
</h:body>
</html>
The browser should get something like:
<html ...>
<head>
<title>Page title here</title>
</head>
<body>
<h2>
the welcome message goes here
</h2>
</body>
</html>
Right?
Well, my browser is getting jsf code (the first piece of code above) and not the html code (the second piece of code above).
It seems to be a configuration problem in netbeans or glassfish but don't know what. Any ideas?
This is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/firstcup/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>greetings.xhtml</welcome-file>
</welcome-file-list>
</web-app>
This is my faces-config.xml file:
<?xml version='1.0' encoding='UTF-8'?>
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config version="2.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<application>
<resource-bundle>
<base-name>firstcup.web.WebMessages</base-name>
<var>bundle</var>
</resource-bundle>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>es</supported-locale>
</locale-config>
</application>
<navigation-rule>
<from-view-id>/greetings.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/response.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
Moreover:
The url I'm entering in the browser is http://localhost:8081/firstcup/ but I've also tried: http://localhost:8081/firstcup/greetings.xhtml
I've checked Glassfish logs and there's no information about not being able to load FacesServlet
If JSF tags are not been parsed, then it simply means that the request has not been passed through the FacesServlet. That servlet is the one responsible for all that JSF stuff. You need to verify if the request URL used matches the url-pattern of the FacesServlet. Note that it is case sensitive.
This may however also happen if you opened the file directly in the builtin browser of the IDE. You shouldn't do that. You need to specify the right URL yourself in the address bar of either the builtin browser or an external browser (e.g. MSIE/Firefox).
Update: one more thing, did you declare the JSF HTML taglib in <html xmlns> attribtue? You omitted that in your code snippet.
It should look like
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
The following code in web.xml
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
instead of faces/* has solved my problem of non-rendered jsf tags.
Note: *.html causes stackoverflow
Check either your web.xml or your faces-config.xml. Something's obviously missing.
edit :
i don't know jsf 2, but in my jsf 1 faces-config.xml i have this :
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
Maybe you should take a look a this. (could be a hint, sorry i cannot help any further)
edit 2 : this is not the answer, sorry
SOLVED: Changing the welcome-file in web.xml to the following solved the problem:
<welcome-file-list>
<welcome-file>firstcup/greetings.xhtml</welcome-file>
</welcome-file-list>
This may not be relevant to you, but after hours of searching for the solution for a similar problem, my culprit turns out to be this file in WEB-INF/faces-config.xml :
<?xml version="1.0"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"/>
For some strange reason JBoss Tools 3.3.0.M2 put that file in my JSF 2.0 project and BOOM! Nothing works. The file looks very innocent yet (probably due to version="1.2") it made me quite frustrated.
I've searched logs (nothing!), WEB-INF/lib, classpaths, even removing dependencies and it turned out to be a single faces-config.xml :-P
Hopefully this helps someone...
I have also suffered from problem of jsf tags, not rendered at all. I used welcome file in web.xml as login/entry.xhtml.
When I changed that file to faces/login/entry.xhtml, it is working well.
It must be due to facesServelet is not intercepting the page.
It leads to rendering of only plain html and jsf tags are simply ignored.
Thanks #hendy-irawan
I solved my issue by changed my faces-config header
From
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
</faces-config>
To
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
</faces-config>
I had the same problem. I deleted some richfaces jars from the WEB-INF/lib and JSF is working now.

Resources