Please disable your adblock and script blockers to view this page

Search this blog

Wednesday 31 October 2012

Passing parameter in XML Resource and Use it in Managed Bean, Using parameterised Resource Bundle in ADF

If we are developing an Fusion Web application and we are thinking about Multilingual application , then the best option i came to know is to use Resource Bundle properties of ADF . When we use resource bundle we have to use labels of Fields and Validation message or any kind of other custom message from a XML file as Resource.xml.
So first you should know that how to configure resource bundle in an ADF Application and there are plenty of posts about configuring Properties or List ResourceBundle.

In this post i will show you that how to pass parameter in XML or how to use Parametrized resource .

Suppose i  have a xml file for ResourceBundle reference Resource.xml--

  1. <?xml version="1.0" encoding="windows-1252" ?>
  2. <bundle>
  3. <label>
  4.     <key>MessageCheck</key>
  5.     <value>Only %s %s %s %s %s allowed</value>
  6.  </label>
  7. </bundle>

and now i use it in managed bean to show a custom message and replace its parameters %s with any desired value then we code like this




  1. //To get String from XML key, resolvElDC is a method to resolve expression language
  2. String message = resolvElDC("#{bundle['MessageCheck']}").toString();
  3. //here replace parameter(%s) in string message with your values
  4. String saveMsg = message.format(message, ",", "/", "@", "_", "%");
  5. //Show FacesMessage
  6. FacesMessage msg = new FacesMessage(saveMsg);
  7. msg.setSeverity(FacesMessage.SEVERITY_INFO);
  8. FacesContext ctx = FacesContext.getCurrentInstance();
  9. ctx.addMessage(null, msg);
  10. // Code for resolvElDC method
  11. public Object resolvElDC(String data) {
  12.     FacesContext fc = FacesContext.getCurrentInstance();
  13.     Application app = fc.getApplication();
  14.     ExpressionFactory elFactory = app.getExpressionFactory();
  15.     ELContext elContext = fc.getELContext();
  16.     ValueExpression valueExp = elFactory.createValueExpression(elContext, data, Object.class);
  17.     return valueExp.getValue(elContext);
  18. }

Now run your code and see the updated message- Only %s %s %s %s%s allowed is now
 
FacesMessage Oracle ADF

Thursday 25 October 2012

Clear af:table Filter Value declaratively in ADF, Reset table filter

When we use table component with filter, and we have to manually clear the data that we search by filter.
but ADF provides functionality to clear filter data by one click on Filter icon.

When We drop table on page and it looks like this

af:table , Tabular data in Oracle ADF

Now we have to set atleast one column with RowHeader --true in propertyInspector of table Column.
It mean select table column and go to property Inspector and Set RowHeader to true



Set Row Header Property of af:table to true

Now run the page, and search something using table filter

Clear filter icon on column that has Rowheader true

Now click on the clear icon that is appearing on head of column , for that we have set RowHeader to true
Click on clear filter icon to reset af:table filter

and your table filter get cleared when you click on that icon.

Cheers :) Happy Learning

Set on Current row after Rollback Execute or page refresh

Some times we edit a table in form and Save(Commit & Execute) or Cancel(Rollback & Execute)  and table refreshed to its first record means focus is now on first row of table.
And we need the same row again, then we search it and perform another operation, this is really disgusting behavior of table for Developer.

To set on previously selected row after execute we can use this code,
in this scenario we have to get current row key from its IteratorBinding and after Execute we can set it again to show that row as selected.





    /**
     * Generic Method to call operation binding
     **/
     public BindingContainer getBindings() {
      return BindingContext.getCurrent().getCurrentBindingsEntry();
     }


     BindingContainer bindings = getBindings();
     //Get Iterator of table
     DCIteratorBinding parentIter = (DCIteratorBinding)bindings.get("IteratorName");
     //Get current row key
     Key parentKey = parentIter.getCurrentRow().getKey();

     //You can add your operation code here, i have used simple Cancel operation 
     //with Rollback and Execute
     
     
     OperationBinding ob= bindings.getOperationBinding("Rollback");
     ob.execute();
     OperationBinding ob1= bindings.getOperationBinding("Execute");
     ob1.execute();
    
     //Set again row key as current row
     parentIter.setCurrentRowWithKey(parentKey.toStringFormat(true));


Monday 22 October 2012

Refresh Page in Oracle ADF by Java Code, Set partial trigger programmatically

Some times we need to refresh whole page , then we can use this managed bean code to refresh whole page in ADF.


    
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;

//Method to reload page
    protected void refreshPage() {

        FacesContext fctx = FacesContext.getCurrentInstance();
        String page = fctx.getViewRoot().getViewId();
        ViewHandler ViewH = fctx.getApplication().getViewHandler();
        UIViewRoot UIV = ViewH.createView(fctx, page);
        UIV.setViewId(page);
        fctx.setViewRoot(UIV);

    }

Partially refresh any UIComponent, Set partial trigger programmatically-




import oracle.adf.view.rich.context.AdfFacesContext;

AdfFacesContext.getCurrentInstance().addPartialTarget(UIComponentBinding);



Wednesday 17 October 2012

Uncommitted/Unsaved Data Warning on page Navigation-Oracle ADF

When we visit some websites and try to close browser tab, it shows warning message like this image

Browser Confirmation Dialog when leaving page 
    To do this in Oracle ADF you have to do nothing complex, if you are using .jspx then it is so simple.

  1. Select af:document from page structure and go to property inspector, now Set UncommitedDataWarning to on.
    af:document tag in Oracle ADF

    UncommittedDataWarning property in ADF
     
    Now when you have uncommitted data in your page and you want to navigate yo other page or want to close same page it will show a message

    When Navigate to another page and page has Uncommitted Data-




    Warning Message when there is unsaved data on page
     
    When try to close tab and page has Uncommitted Data-