Hi Friends,
This blog explains about export you data into excel in ADF .Here in this example i am taking the one of the HR Schema Object Employees and see the how i am implementing this
step by step implementation:
1.Firstly we have to Create EO,VO,AM to the Employees Table and then the Data controls are appeared then drag the Employees vo into the Run page as a Readonly Table. and create the Button inside the table as show in the below Figure.
2. rightclick on the button and adf faces select "Export Collection Action Listener"give
ExportId:Which is the data you are going to export by clicking at the end arrow and give table id
Type :excelHtml bydefault,
Export Rows :no of rows you are going to export.
File Name:File name of the Excel sheet
Title:Title of the excel sheet
After Running the page
Finally the Data in the Employees Table is downloaded into a Excel Sheet
.
ADF internally used the Apche Poy Api for this Exporting data.
Hi Friends,
This blog explains about Image uploading and downloading in a table here i am taking the one of the HR Schema Object Employees and see the how i am implementing this
step by step implementation:
1 .Add a column named as EmployeePicture as BLOB(Binary Large Object) and create Eos, Vos to corresponding Table and add the Corresponding VO to the Application Module which creates the Data Controls.
Here if we add any BLOB kind of the attribute in the DB the corresponding Java class named as BlobDomain in EO, VO.
2. Now i am Creating my EmployyesFormpage.jspx as run page by dragging the Employees vo from the Datacontrols to the UI page as ADF Form
Here we clearly observe means all the attribues are taking as input values
where value of EmployeePicture is #{bindings.Employeepicture.inputValue} we delete this value because it noy value it is input file so we have to create it as input file by selecting the EmployessPicture and convert the attribute to inputFile.
3.Then we have to give autosubmit true to this EmployeePciture label bcacuse the path we selected will have to submit to the EO.
4.Now i creating the value change listener which is pointing to one of the java bean method.#{pageFlowScope.ImageUploadAndDownloadManagedBean.inputFileValueChangeListener} .when the user browse something this valuechangelistener is called .
The valuechangeLsitener will always after the autosubmit true.
Here i am giving the java code for both the FileUpolading and File Downloading but as of now we are just calling the inputFileValueChangeListener method through Value Change Listener
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.binding.AttributeBinding;
import oracle.binding.BindingContainer;
import oracle.binding.ControlBinding;
import oracle.jbo.domain.BlobDomain;
import org.apache.commons.io.IOUtils;
import org.apache.myfaces.trinidad.model.UploadedFile;
public ImageUploadAndDownloadManagedBean() {
}
public void inputFileValueChangeListener(ValueChangeEvent valueChangeEvent) {
UploadedFile file = (UploadedFile) valueChangeEvent.getNewValue();
String fileName = file.getFilename();
DCBindingContainer lBindingContainer =
(DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();
AttributeBinding binding = (AttributeBinding)lBindingContainer.getControlBinding("EmployeePicture");
try {
BufferedInputStream in =
new BufferedInputStream(file.getInputStream());
Long length = file.getLength();
int len = length.intValue();
byte[] data = new byte[len];
int i = 0, k = 0;
if ((in != null)) {
i = in.read(data);
}
in.close();
BlobDomain bd = new BlobDomain(data);
binding.setInputValue(bd);
}catch(Exception e){
e.printStackTrace();
}
}
public void downloadImage(FacesContext facesContext, OutputStream outputStream)
{
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
// get an ADF attributevalue from the ADF page definitions
AttributeBinding attr = (AttributeBinding) bindings.getControlBinding("EmployeePicture");
if (attr == null)
{
return;
}
// the value is a BlobDomain data type
BlobDomain blob = (BlobDomain) attr.getInputValue();
try
{ // copy hte data from the BlobDomain to the output stream
IOUtils.copy(blob.getInputStream(), outputStream);
// cloase the blob to release the recources
blob.closeInputStream();
// flush the outout stream
outputStream.flush();
}
catch (IOException e)
{
// handle errors
e.printStackTrace();
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), "");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
}
Here this uploaded input file just i am coverting to the BLOB Domain and add it to the binding where as the normal input text it is added directly without the valuechangeListener like binding.FirstName.inputValue....
4.And the last thing we have to do is inside your jspx page we have form tag <af:form id="f1" usesUpload="false"> by default it is false we have to make it true <af:form id="f1" usesUpload="true"> by this we are telling to our Framework as this page is of using to upload huge amount of upload files.
Usually the Jsff page will not have the form tag but the page is embedded in the Jspx page at their we have create this operation.
FILE DOWNLOADING:
Now i am creating a button in the EmployeesForm page and named it as Downloadimage and select that button inside adf faces select FileDownLoadActionListener.
content type:image/jpeg(MIME Types)
FileName:EmployeePicture.jpg
Method:#{pageFlowScope.ImageUploadAndDownloadManagedBean.downloadImage}
Here download image is the method that already described in the above business logic.