This post is about to upload single file/multiple files from the client to the server and store the data in a BLOB column in Database.
First of all, wehave tocreate a table to store files in database:
CREATE TABLE "HR"."DOCUMENTS"
(
"DOCUMENT_ID" NUMBER NOT NULL ENABLE,
"DOCUMENT_NAME" VARCHAR2(50 BYTE),
"DOCUMENT_TYPE" VARCHAR2(100 BYTE),
"DOCUMENT_FILE" BLOB,
CONSTRAINT "DOCUMENTS_PK" PRIMARY KEY ("DOCUMENT_ID")
)
Single file upload
Below is the UI for single file upload with atable with uploaded files along with the download buttonfor each file.
Steps to achieve single file uploading:
1.Add inputFile component on jspx page:
<af:inputFile label="Upload File" id="if1"
binding="#{pageFlowScope.SingleFileUploadDownloadBean.inputFile}"
valueChangeListener="#{pageFlowScope.SingleFileUploadDownloadBean.onFileUploadVCL}"
autoSubmit="true"/>
Adda button to trigger the action to upload the File:
<af:commandButton text="Upload" id="cb1"
disabled="#{pageFlowScope.SingleFileUploadDownloadBean.inputFile.value == null ? true : false}"
partialTriggers="if1"
actionListener="#{pageFlowScope.SingleFileUploadDownloadBean.onFileUpload}"
partialSubmit="true"/>
2. Drag and drop the DocumentsVO on page asAdf Table.Remove theBlob column from the table and add a new column in UIto enable File downloading:
//Comment out or remove Blob Column from the table
<!--<af:column sortProperty="DocumentFile" sortable="false"
headerText="#{bindings.DocumentsVO1.hints.DocumentFile.label}"
id="c1">
<af:inputText value="#{row.bindings.DocumentFile.inputValue}"
label="#{bindings.DocumentsVO1.hints.DocumentFile.label}"
required="#{bindings.DocumentsVO1.hints.DocumentFile.mandatory}"
columns="#{bindings.DocumentsVO1.hints.DocumentFile.displayWidth}"
maximumLength="#{bindings.DocumentsVO1.hints.DocumentFile.precision}"
shortDesc="#{bindings.DocumentsVO1.hints.DocumentFile.tooltip}"
id="it1">
<f:validator binding="#{row.bindings.DocumentFile.validator}"/>
</af:inputText>
</af:column>-->
//Add new Column to add Download button in each row
<af:column id="c1" width="413"
headerText="File Download">
<af:commandButton text="Download File" id="cb3">
<af:fileDownloadActionListener contentType="#{row.bindings.DocumentType.inputValue}"
filename="#{row.bindings.DocumentName.inputValue}"
method="#{pageFlowScope.SingleFileUploadDownloadBean.downloadFile}"/>
</af:commandButton>
</af:column>
3.In ManagedBean: (Here bean name isSingleFileUploadDownloadBean)
private RichInputFile inputFile;
private String fileName;
private String contentType;
private UploadedFile file;
private BlobDomain blob;
// Value Change Listener for inputFileComponent
public void onFileUploadVCL(ValueChangeEvent valueChangeEvent) {
file = (UploadedFile)valueChangeEvent.getNewValue();
// Get the file name
fileName = file.getFilename();
// get the mime type
contentType = file.getContentType();
// get blob
blob=getBlob(file);
}
// Method to get Blob
public BlobDomain getBlob(UploadedFile file){
InputStream in = null;
BlobDomain blobDomain = null;
OutputStream out = null;
try
{
in = file.getInputStream();
blobDomain = new BlobDomain();
out = blobDomain.getBinaryOutputStream();
IOUtils.copy(in, out);
}
catch (IOException e)
{
e.printStackTrace();
}
catch (SQLException e)
{
e.fillInStackTrace();
}
return blobDomain;
}
//Method to invoke Operation binding to upload file in database
public void onFileUpload(ActionEvent actionEvent) {
DCBindingContainer bc = ADFUtil.getBindingContainer();
OperationBinding operationbinding = bc.getOperationBinding("uploadFiletoDB");
if(operationbinding!=null){
operationbinding.getParamsMap().put("fileName", fileName);
operationbinding.getParamsMap().put("contentType", contentType);
operationbinding.getParamsMap().put("blob", blob);
operationbinding.execute();
}
System.out.println("File uploaded successfully");
if (inputFile != null) {
inputFile.resetValue();
inputFile.setValid(true);
}
}
//Method to download File
Note: Make sure that Row Selection must be single and in SelectionListener should be present in ADF table on jspx page:
public void downloadFile(FacesContext facesContext,
OutputStream outputStream) {
DCBindingContainer bindings = ADFUtil.getBindingContainer();
DCIteratorBinding iteratorbinding =
bindings.findIteratorBinding("DocumentsVO1Iterator");
BlobDomain blob =
(BlobDomain)iteratorbinding.getCurrentRow().getAttribute("DocumentFile");
try {
IOUtils.copy(blob.getInputStream(), outputStream);
blob.closeInputStream();
outputStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
Multiple files upload :
Here we can addmultiple inputFile component on click of Add Attachment button and remove the same by clicking RemoveAttachment button. By default oneinputFile component will be displayed.And after uploading single/multiple files, on click of Upload Files button, the uploaded files will be stored indatabase.
Steps to achieve multiple files uploading:
1.We will useforEachto add multiple inputFile component
<af:forEach items="#{pageFlowScope.MultipleFileUploadDownloadBean.rowFields}" var="row">
<af:inputFile label="Upload File" id="if2"
binding="#{pageFlowScope.MultipleFileUploadDownloadBean.map['FIELD'].inputFile}"
autoSubmit="true"
valueChangeListener="#{pageFlowScope.MultipleFileUploadDownloadBean.onFileUploadVCL}"
partialTriggers="cb5"/>
</af:forEach>
//Add attachment Button to create new inputFile at runtime
<af:commandButton text="Add Attachment" id="cb4"
actionListener="#{pageFlowScope.MultipleFileUploadDownloadBean.onAddFile}"/>
2. We will create aseparateclass tocreate Multiple inputFile component:
import oracle.adf.view.rich.component.rich.input.RichInputFile;
public class FileUpload {
private RichInputFile inputFile;
public FileUpload() {
super();
}
public void setInputFile(RichInputFile inputFile) {
this.inputFile = inputFile;
}
public RichInputFile getInputFile() {
return inputFile;
}
}
3.InManagedBean:
private List fileNameList = new ArrayList();
private List fileContentTypeList = new ArrayList();
private List fileBlobList = new ArrayList();
private List fileSizeList = new ArrayList();
private List<HashMap> fieldlist = new ArrayList<HashMap>();
private HashMap<String, FileUpload> map;
private int fileCounter = 0;
//Inconstructor addbelow code to add single inputFile componenton first time page load
public MultipleFileUploadDownloadBean() {
map = new HashMap<String, FileUpload>();
try {
FileUpload test = new FileUpload();
map.put("FIELD", test);
fieldlist.add(map);
} catch (Exception e) {
e.printStackTrace();
}
}
//Method to create new InputFile on UI
public void onAddFile(ActionEvent actionEvent) {
map = new HashMap<String, FileUpload>();
try {
FileUpload inputFile = new FileUpload();
map.put("FIELD", inputFile);
fieldlist.add(map);
} catch (Exception e) {
e.printStackTrace();
}
}
//Method to remove inputFile on UI
public void onRemoveFile(ActionEvent actionEvent) {
if (fieldlist.size() > 1) {
fieldlist.remove(fieldlist.size() - 1);
}
}
//Value Change Listener for inputFile
public void onFileUploadVCL(ValueChangeEvent valueChangeEvent) {
UploadedFile file;
file = (UploadedFile)valueChangeEvent.getNewValue();
fileNameList.add(file.getFilename());
fileContentTypeList.add(file.getContentType());
fileSizeList.add(file.getLength());
fileBlobList.add(getBlob(file));
// filecounter to limit no of files that canbe uploaded
fileCounter++;
}
// Method to invoke Operation binding to upload multiple files in database
public void onFileUpload(ActionEvent actionEvent) {
DCBindingContainer bc = ADFUtil.getBindingContainer();
OperationBinding operationbinding =
bc.getOperationBinding("uploadMultipleFilestoDB");
if (operationbinding != null) {
operationbinding.getParamsMap().put("fileNameList", fileNameList);
operationbinding.getParamsMap().put("fileContentTypeList",
fileContentTypeList);
operationbinding.getParamsMap().put("fileBlobList", fileBlobList);
operationbinding.execute();
}
System.out.println("File uploaded successfully");
}
Find the sample apphere
First of all, wehave tocreate a table to store files in database:
CREATE TABLE "HR"."DOCUMENTS"
(
"DOCUMENT_ID" NUMBER NOT NULL ENABLE,
"DOCUMENT_NAME" VARCHAR2(50 BYTE),
"DOCUMENT_TYPE" VARCHAR2(100 BYTE),
"DOCUMENT_FILE" BLOB,
CONSTRAINT "DOCUMENTS_PK" PRIMARY KEY ("DOCUMENT_ID")
)
Single file upload
Below is the UI for single file upload with atable with uploaded files along with the download buttonfor each file.
Steps to achieve single file uploading:
1.Add inputFile component on jspx page:
<af:inputFile label="Upload File" id="if1"
binding="#{pageFlowScope.SingleFileUploadDownloadBean.inputFile}"
valueChangeListener="#{pageFlowScope.SingleFileUploadDownloadBean.onFileUploadVCL}"
autoSubmit="true"/>
Adda button to trigger the action to upload the File:
<af:commandButton text="Upload" id="cb1"
disabled="#{pageFlowScope.SingleFileUploadDownloadBean.inputFile.value == null ? true : false}"
partialTriggers="if1"
actionListener="#{pageFlowScope.SingleFileUploadDownloadBean.onFileUpload}"
partialSubmit="true"/>
2. Drag and drop the DocumentsVO on page asAdf Table.Remove theBlob column from the table and add a new column in UIto enable File downloading:
//Comment out or remove Blob Column from the table
<!--<af:column sortProperty="DocumentFile" sortable="false"
headerText="#{bindings.DocumentsVO1.hints.DocumentFile.label}"
id="c1">
<af:inputText value="#{row.bindings.DocumentFile.inputValue}"
label="#{bindings.DocumentsVO1.hints.DocumentFile.label}"
required="#{bindings.DocumentsVO1.hints.DocumentFile.mandatory}"
columns="#{bindings.DocumentsVO1.hints.DocumentFile.displayWidth}"
maximumLength="#{bindings.DocumentsVO1.hints.DocumentFile.precision}"
shortDesc="#{bindings.DocumentsVO1.hints.DocumentFile.tooltip}"
id="it1">
<f:validator binding="#{row.bindings.DocumentFile.validator}"/>
</af:inputText>
</af:column>-->
//Add new Column to add Download button in each row
<af:column id="c1" width="413"
headerText="File Download">
<af:commandButton text="Download File" id="cb3">
<af:fileDownloadActionListener contentType="#{row.bindings.DocumentType.inputValue}"
filename="#{row.bindings.DocumentName.inputValue}"
method="#{pageFlowScope.SingleFileUploadDownloadBean.downloadFile}"/>
</af:commandButton>
</af:column>
3.In ManagedBean: (Here bean name isSingleFileUploadDownloadBean)
private RichInputFile inputFile;
private String fileName;
private String contentType;
private UploadedFile file;
private BlobDomain blob;
// Value Change Listener for inputFileComponent
public void onFileUploadVCL(ValueChangeEvent valueChangeEvent) {
file = (UploadedFile)valueChangeEvent.getNewValue();
// Get the file name
fileName = file.getFilename();
// get the mime type
contentType = file.getContentType();
// get blob
blob=getBlob(file);
}
// Method to get Blob
public BlobDomain getBlob(UploadedFile file){
InputStream in = null;
BlobDomain blobDomain = null;
OutputStream out = null;
try
{
in = file.getInputStream();
blobDomain = new BlobDomain();
out = blobDomain.getBinaryOutputStream();
IOUtils.copy(in, out);
}
catch (IOException e)
{
e.printStackTrace();
}
catch (SQLException e)
{
e.fillInStackTrace();
}
return blobDomain;
}
//Method to invoke Operation binding to upload file in database
public void onFileUpload(ActionEvent actionEvent) {
DCBindingContainer bc = ADFUtil.getBindingContainer();
OperationBinding operationbinding = bc.getOperationBinding("uploadFiletoDB");
if(operationbinding!=null){
operationbinding.getParamsMap().put("fileName", fileName);
operationbinding.getParamsMap().put("contentType", contentType);
operationbinding.getParamsMap().put("blob", blob);
operationbinding.execute();
}
System.out.println("File uploaded successfully");
if (inputFile != null) {
inputFile.resetValue();
inputFile.setValid(true);
}
}
//Method to download File
Note: Make sure that Row Selection must be single and in SelectionListener should be present in ADF table on jspx page:
public void downloadFile(FacesContext facesContext,
OutputStream outputStream) {
DCBindingContainer bindings = ADFUtil.getBindingContainer();
DCIteratorBinding iteratorbinding =
bindings.findIteratorBinding("DocumentsVO1Iterator");
BlobDomain blob =
(BlobDomain)iteratorbinding.getCurrentRow().getAttribute("DocumentFile");
try {
IOUtils.copy(blob.getInputStream(), outputStream);
blob.closeInputStream();
outputStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
Multiple files upload :
Here we can addmultiple inputFile component on click of Add Attachment button and remove the same by clicking RemoveAttachment button. By default oneinputFile component will be displayed.And after uploading single/multiple files, on click of Upload Files button, the uploaded files will be stored indatabase.
Steps to achieve multiple files uploading:
1.We will useforEachto add multiple inputFile component
<af:forEach items="#{pageFlowScope.MultipleFileUploadDownloadBean.rowFields}" var="row">
<af:inputFile label="Upload File" id="if2"
binding="#{pageFlowScope.MultipleFileUploadDownloadBean.map['FIELD'].inputFile}"
autoSubmit="true"
valueChangeListener="#{pageFlowScope.MultipleFileUploadDownloadBean.onFileUploadVCL}"
partialTriggers="cb5"/>
</af:forEach>
//Add attachment Button to create new inputFile at runtime
<af:commandButton text="Add Attachment" id="cb4"
actionListener="#{pageFlowScope.MultipleFileUploadDownloadBean.onAddFile}"/>
2. We will create aseparateclass tocreate Multiple inputFile component:
import oracle.adf.view.rich.component.rich.input.RichInputFile;
public class FileUpload {
private RichInputFile inputFile;
public FileUpload() {
super();
}
public void setInputFile(RichInputFile inputFile) {
this.inputFile = inputFile;
}
public RichInputFile getInputFile() {
return inputFile;
}
}
3.InManagedBean:
private List fileNameList = new ArrayList();
private List fileContentTypeList = new ArrayList();
private List fileBlobList = new ArrayList();
private List fileSizeList = new ArrayList();
private List<HashMap> fieldlist = new ArrayList<HashMap>();
private HashMap<String, FileUpload> map;
private int fileCounter = 0;
//Inconstructor addbelow code to add single inputFile componenton first time page load
public MultipleFileUploadDownloadBean() {
map = new HashMap<String, FileUpload>();
try {
FileUpload test = new FileUpload();
map.put("FIELD", test);
fieldlist.add(map);
} catch (Exception e) {
e.printStackTrace();
}
}
//Method to create new InputFile on UI
public void onAddFile(ActionEvent actionEvent) {
map = new HashMap<String, FileUpload>();
try {
FileUpload inputFile = new FileUpload();
map.put("FIELD", inputFile);
fieldlist.add(map);
} catch (Exception e) {
e.printStackTrace();
}
}
//Method to remove inputFile on UI
public void onRemoveFile(ActionEvent actionEvent) {
if (fieldlist.size() > 1) {
fieldlist.remove(fieldlist.size() - 1);
}
}
//Value Change Listener for inputFile
public void onFileUploadVCL(ValueChangeEvent valueChangeEvent) {
UploadedFile file;
file = (UploadedFile)valueChangeEvent.getNewValue();
fileNameList.add(file.getFilename());
fileContentTypeList.add(file.getContentType());
fileSizeList.add(file.getLength());
fileBlobList.add(getBlob(file));
// filecounter to limit no of files that canbe uploaded
fileCounter++;
}
// Method to invoke Operation binding to upload multiple files in database
public void onFileUpload(ActionEvent actionEvent) {
DCBindingContainer bc = ADFUtil.getBindingContainer();
OperationBinding operationbinding =
bc.getOperationBinding("uploadMultipleFilestoDB");
if (operationbinding != null) {
operationbinding.getParamsMap().put("fileNameList", fileNameList);
operationbinding.getParamsMap().put("fileContentTypeList",
fileContentTypeList);
operationbinding.getParamsMap().put("fileBlobList", fileBlobList);
operationbinding.execute();
}
System.out.println("File uploaded successfully");
}
Find the sample apphere
相关推荐
英文版的,中文版还在找。貌似中文的ADF设计网上都是付费购买的。。。。
锁相环ADF4001/ADF4002的驱动代码。
ADF4351/4350寄存器计算软件,极大简便ADF435X芯片开发过程!!!
包含ADF4159手册和ADI官方的调试demo。手册是中文版,demo是adi官方的,亲测可用。并且在项目中验证通过
ADF4351配置程序,主要是C51配置ADF5351/4350
1.Web ADF/Web Control 页面ADF框架和页面控件。 2.Web ADF/Common Data Source API 页面ADF框架和普通的数据源API 3.Web ADF/Common Data Source API-->Data Source Specific APIs 页面ADF框架普通数据源API调用...
顾名思义,锁相环(PLL)使用鉴相器比较反馈信号与参考信号,将两个信号的相位锁定在一起。虽然这种特性有许多用武之地,但是PLL如今常用于频率合成,通常充当上变频器/下变频器中的本振(LO),或者充当高速模数转换器...
锁相环ADF4350/4351 altium格式原理图
PLL ADF4350/4351单片机驱动,keil打开
ADF4350 verilog 驱动源代码: ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// ...
基于80c51f芯片控制的频率合成器adf4360-7
ADF4351锁相环例程,能输出35M~4400M的信号
http://www.oracle.com/technetwork/developer-tools/adf/uishell-093084.html
在MATLAB中检验数据的单位根,关于单位根检测的matlab代码
电子设计大赛——ADF4002分频器stm32F1/F4程序,完美实现功能
stm32平台的ADF4002锁相环芯片驱动程序
ADF2
此代码可用于adf检验(This code can be used for ADF verification)
ADF41513 数据手册.PDF
ADF4351设计程序,采用FPGA设计,代码用HDML编写。ADF4351是一款集成了VCO的PLL芯片