Tuesday, May 29, 2018

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;

        }

No comments:

Post a Comment