Tuesday, 25 August 2015

LOV for Transient Attribute in Oracle ADF 11g

Today I will explain how to create LOV on transient attribute.
The scenario is in Employee Table there is no Department Name, but my requirment is in Employee table the department name should as LOV in database it should accept department Id.

For this First created Employee VO on Entity base.Created transient attribute on that VO.

After that I created LOV on that attribue and mapped departmentID aslo.


Create View criteria on Department VO whihc is taking parameter as department id. And that VO into that Employee VO as accessor and shuttule the view vriteria and map the department id to that view criteria.As below

 
In EmployeeViewRowImpl java class write the follwing code in transient getter attribute.
    /**
     * Gets the attribute value for the calculated attribute DepartName.
     * @return the DepartName
     */
    public String getDepartName() {
        RowSet row = this.getDepartmentRVO2();
        Row cuur = row.first();
        String str = (String)getAttributeInternal(DEPARTNAME);
        str = (String)cuur.getAttribute("DepartmentName");
        return str;
    }
In UI drag and drop as LOV. As below.


Thanks..:)




 

Tuesday, 26 May 2015

From Date and To Date accept same Date in ADF

There is regular requirement is, the from date and To date should accept same day(Same date).
And also From date should accept less than the to date and equal like to date also should accept greater than or equal of the from date.

This kind of reqirement we can achieve by UI level.
There is a component is VALIDATE DATE TIME RANGE, but wont work in the case of from date and to date is in same date.

For this kind of requirement we can handle at Entity level is easiest way.

For this I have created validation methods at Entity attribute level from date and to date.


Those methods are pointed to your entity impl classess.


The logic inside methods :

    /**
     * Validation method for Todate.
     */
    public boolean validateTodate(Date todate) {
        if(null != toDateLocal && null != fromDateLocal){
             int compareValue = toDateLocal.compareTo(fromDateLocal);
            if(compareValue == -1 ){
                return false;
            }
        }
        return true;
    }
    /**
     * Validation method for Fromdate.
     */
    public boolean validateFromdate(Date fromdate) {
               if(null != toDateLocal && null != fromDateLocal){
             int compareValue = fromDateLocal.compareTo(toDateLocal);
            if(compareValue == 1 ){
                return false;
            }
        }
        return true;
    }

Here fromDateLocal  and toDateLocal are the class level varibales, should get values from setter and getter.


    /**
     * Gets the attribute value for Fromdate, using the alias name Fromdate.
     * @return the Fromdate
     */
    public Date getFromdate() {
        fromDateLocal = (Date)getAttributeInternal(FROMDATE);
        return (Date)getAttributeInternal(FROMDATE);
    }
    /**
     * Sets <code>value</code> as the attribute value for Fromdate.
     * @param value value to set the Fromdate
     */
    public void setFromdate(Date value) {
        fromDateLocal = value;
        setAttributeInternal(FROMDATE, value);
    }
    /**
     * Gets the attribute value for Todate, using the alias name Todate.
     * @return the Todate
     */
    public Date getTodate() {
        toDateLocal = (Date)getAttributeInternal(TODATE);
        return (Date)getAttributeInternal(TODATE);
    }
    /**
     * Sets <code>value</code> as the attribute value for Todate.
     * @param value value to set the Todate
     */
    public void setTodate(Date value) {
        toDateLocal = value;
        setAttributeInternal(TODATE, value);
    }

In UI you just set auto submit true for from and to date components.

Happy Coding.. :)

Friday, 30 January 2015

Multiple Images Upload and Read In Memory in ADF

Today I would like to explain Multiple images load  and read at a time.
Adf is providing multiple images load at once using input file component only.
It shows the uploaded file in a table format u can remove there also. Awesome feature by ADF
And also it shows the loading status of the images.



For this one most imp porperty is maximumFiles have to be set based on your req.
If you want uplaod any no of files then have to set maximumFiles = -1.

Here My jspx page code:

 <af:commandButton text="Upload Images/ Preview" id="cb1" actionListener="#{viewScope.MultipleImagesUploadBean.loadImages}" />
        <af:inputFile id="if1"  maximumFiles="-1" value="#{viewScope.MultipleImagesUploadBean.uploadFiles}"/>
        <af:forEach items="#{viewScope.MultipleImagesUploadBean.fileNameList}" var="row">
        <af:image source="/images/#{row}" id="i1"
                    partialTriggers="cb1" inlineStyle="width:100px; height:100.0px;"/>
        <af:spacer width="20"/>
        </af:forEach>

Java Code:

    public void loadImages(ActionEvent actionEvent) {
        List<UploadedFile> list = getUploadFiles();
        fileNameList = new ArrayList<String>();
        if(list != null){
            for(int i = 0; i< list.size(); i++){
                System.out.println(list.get(i).getFilename());
                fileNameList.add(list.get(i).getFilename());
                FacesContext fctx = FacesContext.getCurrentInstance();
                ServletContext setvltctx =
                    (ServletContext)fctx.getExternalContext().getContext();
                String imageDirPath = setvltctx.getRealPath("/");
                try {
                    BufferedImage input = ImageIO.read(uploadFiles.get(i).getInputStream());
                    File OutputFile = new File(imageDirPath + "/images/" + fileNameList.get(i));
                    ImageIO.write(input, "PNG", OutputFile);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private List<UploadedFile> uploadFiles;
    private List<String> fileNameList;

    public void setUploadFiles(List<UploadedFile> uploadFiles) {
        this.uploadFiles = uploadFiles;
    }
    public List<UploadedFile> getUploadFiles() {
        return uploadFiles;
    }
    public List<String> getFileNameList() {
        return fileNameList;
    }

















 

Wednesday, 28 January 2015

Upload and Read Image In Memory in ADF

Some times we have requirement when ever user uplaod an image immediately he wants see the preview. So for this requirements  No need any servet class. Here I am Sharing code and process.

JSPX Code:

<af:panelGroupLayout id="pgl1">
          <af:inputFile label="Upload Image" id="if1" autoSubmit="true"
                              valueChangeListener="#{viewScope.MyBean.imageChangeEventInMemory}"/>
          <af:image source="/images/#{viewScope.MyBean.fileName}" id="i1"
                    partialTriggers="if1" inlineStyle="width:100px; height:100.0px;"/>
    </af:panelGroupLayout>

Managed Bean Code:

    public void imageChangeEventInMemory(ValueChangeEvent ve){
        UploadedFile myfile = (UploadedFile)ve.getNewValue();
        fileName = myfile.getFilename();
        FacesContext fctx = FacesContext.getCurrentInstance();
        ServletContext setvltctx =
            (ServletContext)fctx.getExternalContext().getContext();
        String imageDirPath = setvltctx.getRealPath("/");
        try {
            BufferedImage input = ImageIO.read(myfile.getInputStream());
            File OutputFile = new File(imageDirPath + "/images/" + fileName);
            ImageIO.write(input, "PNG", OutputFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

private String fileName;

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }
    public String getFileName() {
        return fileName;
    }


Note:
  You have to create images folder inside web contect folder, just creat empty folder.