Load a property file using message
resource bundle feature inbuilt within the core tag .
Typical example would be to refer to a message value(Login Message), labels etc..
Approach 1 :
Typical example would be to refer to a message value(Login Message), labels etc..
Approach 1 :
f:loadBundle basename="XX_GLOBAL" var="globalres"
Sample as how to refer to the value in a property file using the core tag is
af:outputText value="#{globalres.loginmessage}"
Calling a property file using resource bundle from Backing bean.
public class MyUtilBean {
public String getMessage(String loginmessage) {
FacesContext context = FacesContext.getCurrentInstance();
ResourceBundle bundle = context.getApplication().getMessageBundle();
ResourceBundle resourceBundle = ResourceBundle.getBundle(bundle,Locale.ENGLISH);
String text = resourceBundle.getString(loginmessage);
return text;
}
}
Sample as how to refer to the value in a property file using the core tag is
af:outputText value="#{globalres.loginmessage}"
Calling a property file using resource bundle from Backing bean.
public class MyUtilBean {
public String getMessage(String loginmessage) {
FacesContext context = FacesContext.getCurrentInstance();
ResourceBundle bundle = context.getApplication().getMessageBundle();
ResourceBundle resourceBundle = ResourceBundle.getBundle(bundle,Locale.ENGLISH);
String text = resourceBundle.getString(loginmessage);
return text;
}
}
Approach 2 :
String resoureBundle=
"view.MyBundle";
ResourceBundle resources= BundleFactory.getBundle(resoureBundle);
String msg=null;
if(resources != null)
{
msg= resources.getString("loginmessage");
}
ResourceBundle resources= BundleFactory.getBundle(resoureBundle);
String msg=null;
if(resources != null)
{
msg= resources.getString("loginmessage");
}
Approach 3 :
FacesContext fc = FacesContext.getCurrentInstance();
ResourceBundle resources= fc.getApplication().getResourceBundle(fc,"MyBundle");
bundle.getString("loginmessage");
ResourceBundle resources= fc.getApplication().getResourceBundle(fc,"MyBundle");
bundle.getString("loginmessage");
Approach 4 : (Passing Parameters to the Resource Bundle entires)
No comments:
Post a Comment