Tuesday, May 29, 2018

Using List Array holding list of values and assign it to another VO by createrow

 public List selectedUnits(){
    DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding itr = bindings.findIteratorBinding("CmUserUnitAccessVu1VO1Iterator");
    ViewObject vo = itr.getViewObject();
      //  String unit=new String;
      //String unit[];
      List <String> unit = new ArrayList<String>();
    if(vo!=null){
        Row r[] = vo.getAllRowsInRange();
        for (int i = 0; i < r.length; i++) {
            Boolean check = (Boolean)r[i].getAttribute("TYorN");
            if(check){
                String temp  = (String)r[i].getAttribute("UnitCode");
                unit.add(temp);
               }
        }
    }
    System.out.println("selected units "+unit);
    return unit;
    }



    public void popupUnitProdPrices() {
        DCBindingContainer dcb = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        AppModuleAMImpl am = (AppModuleAMImpl)dcb.getDataControl().getApplicationModule();
        DCIteratorBinding dcibSDtl = dcb.findIteratorBinding("PiUnitProdPriceDtlsVO3Iterator");
        ViewObject voSDtl = dcibSDtl.getViewObject();

        // DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        DCIteratorBinding dcItteratorBindings = dcb.findIteratorBinding("PiProdPriceDefnVO2Iterator");
        ViewObject voDtl = dcItteratorBindings.getViewObject();
        // Get an object representing the table and what may be selected within it
        //DepartmentsVORowImpl row = (DepartmentsVORowImpl)dcItteratorBindings.getCurrentRow();
        PiProdPriceDefnVORowImpl row = (PiProdPriceDefnVORowImpl)dcItteratorBindings.getCurrentRow();
        Row r = voDtl.getCurrentRow();
        if ((row != null) && row.getEntity(0).getEntityState() == Entity.STATUS_NEW) {
            System.out.println("--Status New--");
            if (voSDtl.getRowCount() > 0 && !queryMode) {
                for (int j = voSDtl.getRowCount(); j > 0; j--) {
                    voSDtl.removeCurrentRow();
                }
            }
            List temp = selectedUnits();
            for (int i = 0; i < temp.size(); i++) {
                Row r1 = am.getPiUnitProdPriceDtlsVO3().createRow();
                String vUnit = (String)temp.get(i);
                r1.setAttribute("UnitCode", vUnit);
                r1.setAttribute("ProdPrice", r.getAttribute("ProdPrice"));
                r1.setAttribute("ValidFromDt", r.getAttribute("ValidFromDt"));
            }
        } else {
            System.out.println("--Status Modify--");
        }
        /* int x = 1;
        if (voSDtl.getRowCount() > 0) {
            while (voSDtl.hasNext()) {
                System.out.println("Inside while");
                voSDtl.removeCurrentRow();
                System.out.println(x);
                x++;
            }
            voSDtl.first();
            voSDtl.removeCurrentRow();
        } */

    }

To get Entity State in Managed bean

To get Entity State in Managed bean
-------------------------------------------------------------------------------------------------------------------------------------------

        DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
       DCIteratorBinding dcItteratorBindings = bindings.findIteratorBinding("Departments1Iterator");
       // Get an object representing the table and what may be selected within it
        DepartmentsVORowImpl row = (DepartmentsVORowImpl)dcItteratorBindings.getCurrentRow();
        
        if((row!=null)&& row.getEntity(0).getEntityState()==Entity.STATUS_NEW){
            System.out.println("--Status New--");
        }else{
           System.out.println("--Status Modify--");
        }


another approach

1. first add a new transient attribute in VO CheckRowStatus

in VORowImpl class

 public Integer getCheckRowStatus() {

        byte entityState = this.getEntity(0).getEntityState();

        return new Integer(entityState);

        //return (Integer) getAttributeInternal(CHECKROWSTATUS);

    }


in bean we can validate like this

        int rowStatus = 0;

        if (row1 != null) {

            rowStatus = row1.getCheckRowStatus();

            log.info("rowStatus: " + rowStatus);

        }


ex:

        BindingContainer bindings = getBindings();

        FacesContext fc = FacesContext.getCurrentInstance();

         //#Added by Janardhan Chilukuri on 1st Jul,2021 - Restricting user to save the header before adding line

        DCIteratorBinding dcLineIter = (DCIteratorBinding) bindings.get("XxtwcJuicePlanLineViewIterator");

        XxtwcJuicePlanLineViewImpl vo = (XxtwcJuicePlanLineViewImpl) dcLineIter.getViewObject();

  XxtwcJuicePlanLineViewRowImpl row1 = (XxtwcJuicePlanLineViewRowImpl) vo.getCurrentRow();

        if (!(rowStatus == 1 || rowStatus == 2)) {

            FacesMessage message = new FacesMessage("Please save the changes before adding Juice Ticket lines");

            message.setSeverity(FacesMessage.SEVERITY_WARN);

            fc.addMessage(null, message);

            return null;

        }

Monday, May 21, 2018

EO Level validations Execution when status_new

import oracle.jbo.server.EntityImpl
adf.object.entityState == EntityImpl.STATUS_NEW

or


if (getEntityState() == 0 && PriceType == 'C' && CurFromDt !=null)
  return true;
else
 return false;





/* this expression returns state of current row in collection such as table or treeTable*/
#{row.row.entities[0].entityState}

/*here row is reference variable of collection, this expression returns an int value if it is 
 2-Modified
 0-New
 1-Unmodified
-1-Initialized
*/


---------------------

Effective use of getEntityState() and getPostState() methods in EOImpl class in Oracle ADF

You can use the getEntityState() and getPostState() methods to access the current state of an entity row in your business logic code.

The getEntityState() method returns the current state of an entity row with regard to the transaction

getPostState() method returns the current state of an entity row with regard to the database after using the postChanges() method to post pending changes without committing the transaction.

The sample code is as below

public void postChanges(TransactionEvent transactionEvent) {
    /* If current entity is new or modified */
    if (getPostState() == STATUS_NEW || getPostState() == STATUS_MODIFIED) {
    }
}

The possible outcomes of the getPostState() method are as follows
  • STATUS_UNMODIFIED - if this Entity Object has been queried from the database and is unchanged, or if it has been posted to the database.
  • STATUS_MODIFIED - if this Entity Object has been queried from the database and has changed.
  • STATUS_NEW - if this Entity Object is new and not yet posted to the database.
  • STATUS_INITIALIZED - if this Entity Object is new and the client code marks it to be temporary by calling Row.setNewRowState method.
  • STATUS_DELETED - if this Entity Object has been marked for deletion.
  • STATUS_DEAD - if this Entity Object is new, but has been deleted.

Start date and End date validation at RowImpl class setter methods

public void setStartDate(Date value) {
        String errorMessage = "Start Date should be less than End Date.";
        oracle.jbo.domain.Date other = null;
        java.util.Date otherUtil = null;
        if (value == null) {
            setAttributeInternal(STARTDATE, value);
        } else {
            setAttributeInternal(STARTDATE, value);
            if (null != getAttributeInternal(ENDDATE)) {
                other = (Date)getAttributeInternal(ENDDATE);
                otherUtil = other.getValue();
            } else if (null != getAttributeInternal(ENDDATE)) {
                other = (Date)getAttributeInternal(ENDDATE);
                otherUtil = other.getValue();
            }
            java.util.Date valueUtil = value.getValue();
            if (null != otherUtil && otherUtil.before(valueUtil)) {
                throw new JboException(errorMessage);
            }
            setAttributeInternal(STARTDATE, value);
        }
    }



    public void setEndDate(Date value) {
        if (value == null) {
            setAttributeInternal(ENDDATE, value);
        } else {
            String errorMessage = "End Date should be greater than Start Date.";
            Date other = null;

            java.util.Date otherUtil = null;
            setAttributeInternal(ENDDATE, value);
            if (null != getAttributeInternal(STARTDATE)) {
                other = (Date)getAttributeInternal(STARTDATE);
                otherUtil = other.getValue();
            } else if (null != getAttributeInternal(STARTDATE)) {
                other = (Date)getAttributeInternal(STARTDATE);
                otherUtil = other.getValue();
            }
            java.util.Date valueUtil = value.getValue();
            if (null != otherUtil && otherUtil.after(valueUtil)) {
                throw new JboException(errorMessage);
            }
            setAttributeInternal(ENDDATE, value);
            //  setAttributeInternal(DATEFROM, other);
        }
    }

Friday, May 18, 2018

Set Initial Focus in first field of Af:table

af:table properties --> Display row = selected and Content Delivery = immediate


    /**
        * To set focus in first field of af:table
        *
        */
       public static void setFocusInTableFirstField(RichTable table,String componentId){
           FacesContext facesContext = FacesContext.getCurrentInstance();
           String tableId = table.getClientId(facesContext);
           RowKeySet rks = table.getSelectedRowKeys();
           String inputId = null;
           if (rks != null && rks.size() > 0) {
               Object rowKey = rks.iterator().next();
               String rowId = table.getClientRowKeyManager().getClientRowKey(facesContext, table, rowKey);
               inputId = tableId + ":" + rowId + ":" + componentId;
               System.out.println("@@ClientId Value:" + inputId);
           } else {
               // handle error
           }
         
           ExtendedRenderKitService service = Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
           service.addScript(facesContext,  "   var comp = AdfPage.PAGE.findComponent('"+inputId+"');" +
                                            "   if(comp!=undefined){ comp.focus(); } ");
       }



Add Row Action -->
---------------------
    public oracle.binding.BindingContainer getBindings() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();
    }

    public String detailAddRow_action() {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = bindings.getOperationBinding("CreateInsert1");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        ReusableCode.setFocusInTableFirstField(getT1(), "prodCodeId");
        return null;
    }

Java script file Copy field from previous field

create this javascript file under ViewController

/*F9 lov function*/
function showMyLOV(event) {
  var source = AdfPage.PAGE.getActiveComponent();
  if (event.getKeyCode() == AdfKeyStroke.F9_KEY) {
      if (source.getTypeName() == "AdfRichInputListOfValues") {
            AdfLaunchPopupEvent.queue(source, true);
            src = event.getSource();
            //AdfDhtmlInputListOfValuesPeer.FocusNextElement(popId);
            //event.cancel();
      }else if(source.getTypeName() == "AdfRichInputDate"){
        src = event.getSource();
        var subId = AdfRichUIPeer.CreateSubId(src.getClientId(), AdfDhtmlInputDatePeer._POPUP_ID);
        var b1ComponentRef = AdfPage.PAGE.findComponentByAbsoluteId(subId);
        hints = {alignId:src.getClientId(), align:AdfRichPopup.ALIGN_END_BEFORE};
        b1ComponentRef.show(hints);
        event.cancel();
      }
    }
}


/**
 * Copy field from previous field
 */

 function copyPrevious(event){
    keyCode = event.getKeyCode();
    var curItem = event.getSource();
 
if (keyCode == AdfKeyStroke.F8_KEY){
 
     var ac = AdfPage.PAGE.getActiveComponent();
 
     var parent = ac.getParent();
   
            while (parent)  {
              if (parent instanceof AdfRichTable) {
                  break;
              }
               parent = parent.getParent();
             }
   
     if (parent instanceof AdfRichTable) {
       
          //using a matcher to split up the clientId so we can calculate the new clientId we want to navigate to
          var clientId = ac.getClientId().match("(.*):([0-9]+)(:[^:]+)");
          var newRowKey
          var tablePeer  = parent.getPeer();
          tablePeer.bind(parent);
          newRowKey1 = tablePeer._getPreviousRowKeyAndRow(clientId[2]).rowKey;
          newRowKey = tablePeer._getNextRowKeyAndRow(clientId[2]).rowKey;
       
          //nextSibling
          var id = clientId[1]+":"+newRowKey1+":"+curItem.getId();
          var copyItem = AdfPage.PAGE.findComponentByAbsoluteId(id);
          //alert(clientId[1]+" --- "+clientId[2]+" "+newRowKey+" "+newRowKey1+" "+id+" "+copyItem+" "+curItem);

  if(copyItem!=null){
  var value = copyItem.getValue();
  curItem.setValue(value);
  }else{
                    alert('Nothing to copy'+id);
                   }

          //event.cancel();
        }
    }
}


we need drop client listener where ever we want

<af:clientListener method="copyPrevious" type="keyDown"/>




===================
How to move to first attribute when I reaches to last attribute
===================
function navigateToFirstField(evt) {
          keyCode = evt.getKeyCode();
          if (keyCode == AdfKeyStroke.TAB_KEY) {
              //alert('Enterde into JS Code');
              var lastField = evt.getSource();
              var firstField = lastField.findComponent("prodCodeId");
              firstField.focus();
              evt.cancel();
          }
      }
=======================

Thursday, May 17, 2018

Bounded Attribute Value

    public Map getBoundAttributeValue() {
        return new HashMap() {
            @Override
            public Object get(Object attrName) {
                Object attrVal = ADFUtils.getBoundAttributeValue((String)attrName);
                return attrVal;
            }

            @Override
            public Object put(Object attrName, Object attrVal) {
                ADFUtils.setBoundAttributeValue((String)attrName, attrVal);

                return null;
            }
        };
    }

at Value property
#{backingBeanScope.backing_PriceDefinition.boundAttributeValue['Remarks']}

at Disable property
#{backingBeanScope.backing_PriceDefinition.boundAttributeValue['PriceCntrlNo'] eq null}

Thursday, May 3, 2018

Getting Financial year for today's date

    public String getFinYear(Date reqDt) {
        String finYr = null;
        String sql =
            "SELECT finyr_code FROM cm_finyr_mst WHERE  ? BETWEEN FINYR_FROM_DT AND FINYR_TO_DT AND ROWNUM=1";
        PreparedStatement preparedStatement = this.getDBTransaction().createPreparedStatement(sql, 0);
        try {
            //preparedStatement.setString(1, compCode);

            System.out.println("Invoice date:" + reqDt);
            //SimpleDateFormat dt1 = new SimpleDateFormat("dd-MM-yyyy");
            //String date = dt1.format(invdt);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            java.util.Date d1 = null;
            try {
                d1 = dateFormat.parse(reqDt.toString());
            } catch (ParseException e) {
                e.printStackTrace();
            }
            java.sql.Date sqlDate = new java.sql.Date(d1.getTime());
            System.out.println("Requisition date2:" + d1);
            preparedStatement.setDate(1, (java.sql.Date)sqlDate);
            ResultSet rs = preparedStatement.executeQuery();
            rs.next();
            finYr = rs.getString(1);
        } catch (SQLException sqle) {
            sqle.printStackTrace();
        }
        System.out.println("Financial Year Code:"+finYr);
        return finYr;
    }