Sunday 9 June 2019

Read Property files in jsff and java class in ADF project

Hi

We often have the requirement of reading properties from a file placed inside the ADF application itself . We use this mainly for easy access of properties that uses in many locations across the application.


Code to read property file  in java:

  InputStream st = null;
 Properties prop = new Properties();
 st =
    Thread.currentThread().getContextClassLoader().getResourceAsStream("/com/view/read.properties);

 try {
           prop.load(st);
          String personID=prop.getProperty("Employee") ;;

 
         }catch (Exception e) {
           logErrorStackTrace(e);
            }finally{
                try{
                    if (st !=null) {
                        st .close();
                    }
               
                }catch (Exception e) {
                    logErrorStackTrace(e);
                }
            }

*Must close the st  after usage

Code to read property file  in jsff:

Declaration / import :
 
 <c:set var="propfile"

           value="#{adfBundle['com.view.read']}"/> // read is the property file name

Usage:

            <af:outputText value="#{propfile.outputtext}"
                            id="ol1"/>


Thank You!!

Never stop learning ...

Read Property files in JAVA/ ADF from external location

Hi

We often have the requirement of reading properties from a file placed in external location of server . This always helps to make the changes in application with out down time.

Say , If you have configured a property named  "PROMOAVAILABLE" in property files and is set to ON if promotion is applicable and OFF if not applicable.
Based on this you can alter your logic in the code and there will be no re deployments necessary.


code to read property file :

 FileInputStream fileInputStream= null;

    try {

          File file=new  File("/opt/oracle/read.properties"); // Property file location
          fileInputStream= new FileInputStream(file);
          ResourceBundle resource = new PropertyResourceBundle(fileInputStream);
          String promo=resource.getString("PROMOAVAILABLE") ;

           if("ON".equalsIgnoreCase(promo)){
                         //write code
                }
        else{
                         //write code
              }

         }catch (Exception e) {
           logErrorStackTrace(e);
            }finally{
                try{
                    if (fileInputStream !=null) {
                        fileInputStream.close();
                    }
                 
                }catch (Exception e) {
                    logErrorStackTrace(e);
                }
            }

*Must close the FileInputStream after usage 

Hello World in Java and Go

Hello World: Java: public class HelloWorld { public static void main (String[] args) { System.out.println( "Hello, W...

Popular Posts