Search This Blog

Friday, September 30, 2011

loading and passing parameters to messages using resource bundle in ADF page


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 :

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;
}
}

 

Approach 2 :

String resoureBundle= "view.MyBundle";
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");


Approach 4 :  (Passing Parameters to the Resource Bundle entires)
 
oracle.jbo.common.StringManager.getString ("view.MyBundle", "loginmessage","No Match Found", new String[] {Param1Value, Param2Value .......});

Thursday, September 29, 2011

OAF - Calling Database sequence

Calling a Database sequence.
Traditional way of calling a sequence was to create a View object with a "select sequence.nextval as seqvalue from dual" and call something like below.

OAViewObject vo = (OAViewObject)am.findViewObject("sequencename");
OARow row = (OARow) vo.first();
Number seqvalue = row.getAttribute("seqvalue"));

But instead oracle provides a direct API to get the value of the sequence and can be used as below.

// Calling from within an Application Module.
OADBTransaction trx = getOADBTransaction();
Number seqnum = transaction.getSequenceValue("sequencename");

//Calling from controller
OAApplicationModule am = (OAApplicationModule)pageContext.getApplicationModule(webBean);
OADBTransaction transaction = (OADBTransaction)am.getOADBTransaction();
Number seqvalue= transaction.getSequenceValue("sequencename");

OAF - String to SQL Date

Convert the String object to java.sql.Date object using stringToDate() function from oracle.apps.fnd.framework.OANLSServices class like below.

java.sql.Date getClientSysdate(){
OADBTransaction trx =
(OADBTransaction)getApplicationModule().getTransaction();
OANLSServices nls = trx.getOANLSServices();
oracle.jbo.domain.Date serverDate = trx.getCurrentDBDate();

java.util.Date javaClientDate = nls.getUserDate(serverDate);
long longDate = javaClientDate.getTime();
return new java.sql.Date(longDate);
}