Thursday, October 28, 2010

ADF UI - Accessing properties file or resource bundle in java bean

If we directly refer to resource bundle in jsf page by using 'Select text resource..' option available, the c:set tag will be added to the jsff page and we'll use the bundle properties using it's 'var' as a reference.
<?xml version='1.0' encoding='windows-1252'?> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich" xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core"> <c:set var="demouiBundle" value="#{adfBundle['com.demo.ui.DemoUiBundle']}"/> <af:panelGroupLayout id="pgl1"> <af:showDetailHeader text="#{demouiBundle['Header.Title']}" disclosed="true" id="sdh1"> <f:facet name="context"/> <f:facet name="menuBar"/> <f:facet name="toolbar"/> <f:facet name="legend"/> <f:facet name="info"/> </af:showDetailHeader> <af:showDetailHeader text="#{pageFlowScope.ExampleBean.headerTitle}" disclosed="true" id="showDetailHeader1"> <f:facet name="context"/> <f:facet name="menuBar"/> <f:facet name="toolbar"/> <f:facet name="legend"/> <f:facet name="info"/> </af:showDetailHeader> </af:panelGroupLayout> </jsp:root>


But, some times there might be needs to refer the properties bundle from java bean to access a property.

This can be done by using the below code.
package com.demo.beans; import java.util.ResourceBundle; import oracle.javatools.resourcebundle.BundleFactory; public class ExampleBean { public String getHeaderTitle() { ResourceBundle rs = BundleFactory.getBundle("com.demo.ui.DemoUiBundle"); return rs.getString("Header.Title"); } }


Content of the sample bundle file:
# sample properties Header.Title=Employee Details EMP_NAME=Employee Name DEPT_NAME=Department Name


Running the above jsff, we'll get the same text by using java bean as well direct reference in jsff (Screen shot below).

7 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Please let me know if we can update the resource bundle programmatically. For example adding a key, value pair of properties through java code.

    ReplyDelete
  3. You will educate how to troubleshoot projects and love lessons in differed zones indicated as duds. java

    ReplyDelete
  4. A selection of homes for sale is an ideal investment for a second home abroad. Property in Greece is consistently popular with overseas buyers the main regions of interest are.Source

    ReplyDelete
  5. Some properties in need of refurbishment in Hull can be bought for as little as 20K. deyaar midtown project

    ReplyDelete

Related Posts with Thumbnails