-1

I read this Where to place and how to read configuration resource files in servlet based application? and more but i dont have a java class, i only have xhtml page to get messages from property. I put properties fcile into webcontent, src, package in src, meta inf but none of them worked.

the xhtml page:

  <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />



<title>#{msgs.windowTitle}</title>
</head>
<body>
<h:form>

<h:panelGrid columns="2" columnsClasses="evenColumns, oddColumns">

#{msgs.namePrompt}
<h:inputText/>

#{msgs.PasswordPrompt}
<h:inputSecret id="password" />

#{msgs.ConfirmPasswordPrompt}
<h:inputSecret id="passwordConfirm"/>

</h:panelGrid>

<h:commandButton type="button" value="Submit" onclick="checkPassword(this.form)" />
    </h:form>
    </body>

</html>

facesconfig:

    <?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">
<application>
              <message-bundle>messages</message-bundle>

           </application>
</faces-config>

checkPassword.js (i put in webcontent, i couldnot have time for to find where to put js, i first want to find out properties)

  /**
 * 
 */

function checkPassword(form){
    var password = form[form.id+":passwordConfirm"].value;

    var passwordConfirm = form[form.id+":password"].value;
    if(password==passwordConfirm){
        form.submit();
    }
    else{
        alert("Wrong");
    }


}

I use eclipse kepler jsf 2.2. Apache tomcat 7.0.54

When i run, it only shows input texts, not title or other texts. What can be the reason?

I changed also a lot of times name of file. Messages, msgs, messages and declaration but still did not work.

Community
  • 1
  • 1

2 Answers2

0

There are three things you can do for i18n in JSF: In this case the file messages.properties must be placed in a package called: src/your/package/name/ . Change this to your needs.

  1. Define the message files in faces-context.xml:

    <locale-config>
     <default-locale>en</default-locale>
     <supported-locale>de</supported-locale>
     <supported-locale>cn</supported-locale>
    </locale-config>
    <resource-bundle>
     <base-name>your.package.name.messages</base-name>
     <var>msgs</var>
    </resource-bundle>
    
  2. Or use the format-taglib to load the bundle:

    <f:loadBundle basename="your.package.name.messages" var="msgs" />
    
  3. Or create a bean yourselft using the ResourceBundle class.

Stefan
  • 12,108
  • 5
  • 47
  • 66
  • 1
    Did not work resourcebunle. I put core package , inside name folder. inside messages.properties file –  Jun 23 '14 at 10:59
0

try to put this inside faces-config:

  <application>
      <resource-bundle>
              //  try to put inside main/java/resources
        <base-name>com.x.messages</base-name>
        <var>msg</var>
       </resource-bundle>
     </application>

and then for especial bundle you can specify a bundle for view:

f:loadBundle basename="com.x.messages" var="msg"/>
ZaoTaoBao
  • 2,567
  • 2
  • 20
  • 28
  • Did not work application one. I put core package , inside name folder. inside messages.properties file –  Jun 23 '14 at 10:59
  • maybe you can try to recuperate via java code de resource bundle and debug take a look : http://docs.oracle.com/javase/7/docs/api/java/util/ResourceBundle.Control.html – ZaoTaoBao Jun 23 '14 at 11:46