Tuesday, April 16, 2019

Disable future Date on ADF “inputDate” Component

http://www.adftutorials.com/disable-future-date-on-adf-inputdate-component.html


Sometimes we need to disable future date on ADF inputDate Component so that, a user is unable to select date after the current date.
For this purpose we can use ADF inputDate component MaxValue property. Here’s a small step by step tutorial to achieve this requirement.
Step1:- drag-drop ADF inputDate component on jspx page from component palette.
Step2:- create following method on backing bean class which return oracle.jbo.domain.Date type  currentDate.

Step3:- select inputDate component on jspx page and go to property inspector  MaxValue select Expression Builder select currentDate function.

1
Now when you’ll run the program, you be able to see that the  future date is disabled. User will be able to select the dates  before the current date.
2

If user manually enters the date, it’ll validate the date and will display a validation message.
3

Wednesday, March 13, 2019

lock

    public void lock() {
        try {
            super.lock();
        } catch (oracle.jbo.RowInconsistentException e) {
            if (e.getErrorCode().equals("25014")) {
                super.lock();
            } else
                throw e;
        }
    }

Monday, February 18, 2019

Getting selected value (not index) & display value of select one choice programmatically in ADF

Hello All,
This post is about a common requirement of getting selected value & display value of af:selectOneChoice in the managed bean
normally when we try to get selected value of  selectOneChoice in the managed bean (in ValueChange/ Validator or using binding) it returns the index of that row
so there is a little piece of code using that we can get selected value of choice component


    • I have used Departments table of HR Schema in the sample and created a lov on a transient field


    • Now dropped that ViewObject on the page as a table


    • Created a value change listener in managed bean fro DeptIdTrans but it returns the index of the selected value


    • Then i googled about it and used this method to solve my headache, try to get attributeValue instead of inputValue, see the code written in valueChaneListener in managed bean
/**Value Change Listener of DeptIdTrans (to get selected and display value)
     * @param vce
     */
    public void deptIdVCE(ValueChangeEvent vce) {
        System.out.println("New Value is-" + vce.getNewValue());
        if (vce.getNewValue() != null) {
            this.setvalueToExpression("#{row.bindings.DeptIdTrans.inputValue}",
                                      vce.getNewValue()); //Updating Model Values
            Integer selectedCode =
                Integer.parseInt(this.getValueFrmExpression("#{row.bindings.DeptIdTrans.attributeValue}").toString());

System.out.println("******** Selected Value in List***** " + selectedCode);
System.out.println("*******Display Value in List ****" +
getValueFrmExpression("#{row.bindings.DeptIdTrans.selectedValue.attributeValues[1]}"));

        }
    }


  • There is two methods to set and get value in expression (EL)

 /**Method to set value in Expression (EL)
     * @param el
     * @param val
     */
    public void setvalueToExpression(String el, Object val) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ELContext elContext = facesContext.getELContext();
        ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
        ValueExpression exp = expressionFactory.createValueExpression(elContext, el, Object.class);
        exp.setValue(elContext, val);
    }

    /**Method to get value from Expression (EL)
 * @param data
 * @return
 */
    public String getValueFrmExpression(String data) {
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = fc.getELContext();
ValueExpression valueExp = elFactory.createValueExpression(elContext, data, Object.class);
String Message = null;
Object obj = valueExp.getValue(elContext);
        if (obj != null) {
Message = obj.toString();
        }
        return Message;
    }



  • Again run the page and select any value in selectOneChoice (LOV) and see the result
Getting selected value

Tuesday, February 12, 2019

populate data into af:table with createrowsetiterator

        ViewObject vo = CommonCode.getViewObjectByIteratorName("PosCustomerInfoVuVORef1Iterator");
        RowSetIterator iter =  vo.createRowSetIterator(null);
       
        DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        DCIteratorBinding itr = bindings.findIteratorBinding("PiCustOfferDtlVO2Iterator");
        ViewObject voc = itr.getViewObject();
       
         while(iter.hasNext()){
             Row rw = iter.next();
             String isSelected = (String)rw.getAttribute("TSelectCust");
             BigDecimal custid = (BigDecimal)rw.getAttribute("CustId");
             String custcode = (String)rw.getAttribute("CustCode");
             if(isSelected!=null && "Y".equals(isSelected)){
                if(custid!=null){
                    Row rw1 = voc.createRow();
                    System.out.println("custid *****"+custid);
                    rw1.setAttribute("CustId", custid);
                    rw1.setAttribute("CustCode", custcode);
                    rw1.setAttribute("CustOfferPromoCode", generatePromoCode());
                    System.out.println("custid ***** CustOfferPromoCode "+ rw1.getAttribute("CustOfferPromoCode"));
                   
                    voc.insertRow(rw1);
                }
             } /* else{
                 CommonCode.errmsg("Please Select Categories", null);
             }  */
         
         }
        iter.closeRowSetIterator();

viewcriteria applying for VO

        ViewObject vo= ReusableMethodsClass.getAM().findViewObject("PosCustomerInfoVuVORef1");
        DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        DCIteratorBinding dcItteratorBindings = bindings.findIteratorBinding("PosCustomerInfoVuVORef1Iterator");
        // Get an object representing the table and what may be selected within it
        ViewObjectImpl voi = (ViewObjectImpl)dcItteratorBindings.getViewObject();
        ViewCriteria vc = voi.getViewCriteria("PosCustomerInfoVuVORefCriteriaCustType");
        voi.applyViewCriteria(vc);
        voi.setNamedWhereClauseParam("pcompcust", compcode);
        voi.setNamedWhereClauseParam("pcusttype", "N");
        vo.executeQuery();
        System.out.println("no of rows vo.getFetchedRowCount() "+vo.getFetchedRowCount());

Monday, January 28, 2019

ADF Table Filter Case Insensitive and Search by Contains Instead of Start With

ADF Table Filter Case Insensitive and Search by Contains Instead of Start With

In ADF table if you enable column filter this filter by default will search by "start with" and it will be case sensitive . For example in table employees if you have employee name = Hermann and you try to search by "man", the search will return no result


but if you search by "Herm" it will return result


If you try to search by "herm" it will return no result.



This is because the filter by default is case sensitive and will search by start with.

In many cases we need the all tables filters be case insensitive and search by contains not start with. You can search by case insensitive by setting filterFeatures="caseInsensitive" for  each af:column but you need to do this in all af:column in your application and it will not be a proper solution.

You can search with contains by typing your string between '%', but we need something to be more easy than typing %.

To make the the ADF table filter be case insensitive and search by contains follow these steps:

1- In model project create new class "CustomViewImpl" this class should extend oracle.jbo.server.ViewObjectImpl


2- In this class override getCriteriaItemClause(ViewCriteriaItem viewCriteriaItem) and write this code:

public String getCriteriaItemClause(ViewCriteriaItem viewCriteriaItem)
{
if (viewCriteriaItem.getAttributeDef().getJavaType().getName().equals("java.lang.String"))
{
viewCriteriaItem.setValue("%" + viewCriteriaItem.getValue() + "%");
}
viewCriteriaItem.setUpperColumns(true);
return super.getCriteriaItemClause(viewCriteriaItem);
}
view rawCustomViewImpl.java hosted with ❤ by GitHub




3- Go to Model --> Project Properties --> ADF Business Components --> Base Classes --> View Object --> change Object to point to your CustomViewImpl class


4- Open ViewObject --> Java --> Java Classes --> Generate View Object Class



5- If you open the generated ViewImpl class you will find it extend the CustomViewImpl class


6- Run the application and test.

custom generic class in model level

import oracle.jbo.ViewCriteriaItem;
import oracle.jbo.server.ViewObjectImpl;

public class CustomViewImpl extends ViewObjectImpl {
    /**
     * Added   for filtering data in Grid using filters.
     * */
    @Override
    public String getCriteriaItemClause(ViewCriteriaItem viewCriteriaItem) {
        if (!viewCriteriaItem.getValue().toString().startsWith(":")) {
            if (viewCriteriaItem.getValue() != null &&
                viewCriteriaItem.getAttributeDef().getJavaType().getName().equals("java.lang.String")) {
                viewCriteriaItem.setValue("%" + viewCriteriaItem.getValue()+ "%");
            }
        }
        viewCriteriaItem.setUpperColumns(true);
        return super.getCriteriaItemClause(viewCriteriaItem);
    }
}


--  --- this method need to write at voimpl class

    public String getCriteriaItemClause(ViewCriteriaItem viewCriteriaItem) {
        System.out.println("--- one");
        String vl=(String)viewCriteriaItem.getValue();
        System.out.println("--- get value :  "+  viewCriteriaItem.getValue()+"  val : "+vl);
        if(viewCriteriaItem.getValue()!=null && !viewCriteriaItem.getValue().toString().startsWith(":")){
            System.out.println("-- start with :");
            if(viewCriteriaItem.getValue()!=null && viewCriteriaItem.getAttributeDef().getJavaType().getName().equals("java.lang.String")){
                viewCriteriaItem.setValue("%" + viewCriteriaItem.getValue());
            }
        }
        viewCriteriaItem.setUpperColumns(true);
        return super.getCriteriaItemClause(viewCriteriaItem);
    }




--- this is another way


ADF: case insensitive filtering in af:table

 
We have default sorting and filtering options in adf table. But table filters are case sensitive by default. If we need to make the filters as case insensitive, we have simple option with properties. We no need to write any custom code to achieve this.
In properties we have filterFeatures attribute. For that we need to declare “caseInsensitive” like below :

Thats all. We got the case insensitive for adf table filters .

Monday, January 21, 2019

totals calculating with rounding 2

new BigDecimal(FaTransDtl.sum('TransAmt') == null ? 0 : FaTransDtl.sum('TransAmt') ).setScale(2,BigDecimal.ROUND_HALF_EVEN)


If u want sum on same VO

object.getRowSet().sum('ExpnsAmt != null ? ExpnsAmt : 0 ')

https://adfindepth.blogspot.com/2019/01/groovy-examples-in-adf-column-sum-using.html

new BigDecimal(object.getRowSet().sum('DrcrTag=="D"?(TransAmt != null ? TransAmt : 0 ):0')).setScale(2, BigDecimal.ROUND_HALF_EVEN)