آموزش

All posts tagged آموزش

ساخت فایل zip در داخل برنامه جاوا zip file build in java adf

ساخت فایل zip در داخل برنامه جاوا zip file build in java adf

از کد زیر میتوانید برای ساخت فایل zip استفاده نمایید.

package test;</p>
<p>import java.io.File;<br />
import java.io.FileInputStream;<br />
import java.io.FileNotFoundException;<br />
import java.io.FileOutputStream;<br />
import java.io.IOException;<br />
import java.util.zip.ZipEntry;<br />
import java.util.zip.ZipOutputStream;</p>
<p>public class ZipFiles {</p>
<p>public static void main(String[] args) {</p>
<p>try {<br />
FileOutputStream fos = new FileOutputStream("atest.zip");<br />
ZipOutputStream zos = new ZipOutputStream(fos);</p>
<p>String file1Name = "file1.txt";<br />
String file2Name = "file2.txt";<br />
String file3Name = "folder/file3.txt";<br />
String file4Name = "folder/file4.txt";<br />
String file5Name = "f1/f2/f3/file5.txt";</p>
<p>addToZipFile(file1Name, zos);<br />
addToZipFile(file2Name, zos);<br />
addToZipFile(file3Name, zos);<br />
addToZipFile(file4Name, zos);<br />
addToZipFile(file5Name, zos);</p>
<p>zos.close();<br />
fos.close();</p>
<p>} catch (FileNotFoundException e) {<br />
e.printStackTrace();<br />
} catch (IOException e) {<br />
e.printStackTrace();<br />
}</p>
<p>}</p>
<p>public static void addToZipFile(String fileName, ZipOutputStream zos) throws FileNotFoundException, IOException {</p>
<p>System.out.println("Writing '" + fileName + "' to zip file");</p>
<p>File file = new File(fileName);<br />
FileInputStream fis = new FileInputStream(file);<br />
ZipEntry zipEntry = new ZipEntry(fileName);<br />
zos.putNextEntry(zipEntry);</p>
<p>byte[] bytes = new byte[1024];<br />
int length;<br />
while ((length = fis.read(bytes)) &gt;= 0) {<br />
zos.write(bytes, 0, length);<br />
}</p>
<p>zos.closeEntry();<br />
fis.close();<br />
}</p>
<p>}
خواندن بیشتر
royal visionساخت فایل zip در داخل برنامه جاوا zip file build in java adf

نحوه استفاده از af:listView زمانیکه جدول داریم، بهترین کامپوننت برای فضای موبایل و تبلت چیدمان صفحه شبیه به اندروید و اپل

نحوه استفاده از کامپوننت af:listView برای نمایش رکوردهای یک ViewObject بصورت یک لیست که مشابه به اندروید و اپل باشد در این حالت با اسکرول صفحه رکورد های بعدی را میبیند.

List View – Cool Looking Component for Collections post by:http://andrejusb.blogspot.com

I’m very excited about ADF release, it brings new freshness and coolness feeling to ADF. ADF Faces runtime performance seems to be incomparable faster and much more responsive comparing to previous ADF 11g R1 and even ADF 11g R2 releases. This gives good hopes to expect the same improvements in ADF 12c. There is new ADF Faces component introduced – List View. You can think about it as about much more liberal ADF Faces table component. List View renders data collections but there is much more control and flexibility how data collection is presented visually. If you need to render strict tabular data – ADF Faces table is the most suitable, List View is for something less structured. We could achieve up till now similar layout as List View with custom implementation using ADF Faces iterators or for each tags. Of course it is much easier now to use out of the box List View tag – Displaying a Collection in a List.

 

Here you can see fragment structure for my sample application with List View usage – ListViewApp.zip:

1 - نحوه استفاده از af:listView زمانیکه جدول داریم، بهترین کامپوننت برای فضای موبایل و تبلت چیدمان صفحه شبیه به اندروید و اپل

There are two types of List View implemented here – simple and hierarchical one. Simple List View renders collection in a list, there is option to load more rows from the collection on demand. Hierarchical List View renders Department – Employees master detail data:

2 - نحوه استفاده از af:listView زمانیکه جدول داریم، بهترین کامپوننت برای فضای موبایل و تبلت چیدمان صفحه شبیه به اندروید و اپل

Simple list is configured with the same property values as regular ADF Faces table:

3 - نحوه استفاده از af:listView زمانیکه جدول داریم، بهترین کامپوننت برای فضای موبایل و تبلت چیدمان صفحه شبیه به اندروید و اپل

Collection row is rendered within List View using List Item tag – this is where actual output or input ADF Faces component is implemented:

4 - نحوه استفاده از af:listView زمانیکه جدول داریم، بهترین کامپوننت برای فضای موبایل و تبلت چیدمان صفحه شبیه به اندروید و اپل

List View with editable popup functionality – launched from Edit button. Edited data is synchronized with data rendered in List View immediately:

5 - نحوه استفاده از af:listView زمانیکه جدول داریم، بهترین کامپوننت برای فضای موبایل و تبلت چیدمان صفحه شبیه به اندروید و اپل

Hierarchical List View is configured with the same properties as regular ADF Faces tree would be configured – pointing to treeModel instead of collectionModel as for the ADF Faces table. There is groupHeaderStamp facet – it allows to render data grouping:

6 - نحوه استفاده از af:listView زمانیکه جدول داریم، بهترین کامپوننت برای فضای موبایل و تبلت چیدمان صفحه شبیه به اندروید و اپل

Second level data is rendered under List Item tag:

7 - نحوه استفاده از af:listView زمانیکه جدول داریم، بهترین کامپوننت برای فضای موبایل و تبلت چیدمان صفحه شبیه به اندروید و اپل

In the page definition, there is regular tree collection definition as usual:

8 - نحوه استفاده از af:listView زمانیکه جدول داریم، بهترین کامپوننت برای فضای موبایل و تبلت چیدمان صفحه شبیه به اندروید و اپل

Hierarchical List View provides really good view of hierarchical data and it renders fast. Here viewing employees by departments:

9 - نحوه استفاده از af:listView زمانیکه جدول داریم، بهترین کامپوننت برای فضای موبایل و تبلت چیدمان صفحه شبیه به اندروید و اپل

One more small thing: I noticed in PS6 after session timeout – screen becomes black, looks good:

10 - نحوه استفاده از af:listView زمانیکه جدول داریم، بهترین کامپوننت برای فضای موبایل و تبلت چیدمان صفحه شبیه به اندروید و اپل
خواندن بیشتر
royal visionنحوه استفاده از af:listView زمانیکه جدول داریم، بهترین کامپوننت برای فضای موبایل و تبلت چیدمان صفحه شبیه به اندروید و اپل

نحوه استفاده از fileDownloadActionListener برای دانلود کردن فایل در داخل Oracle ADF (گرفتن پیوست و attachment)

برای دانلود کردن فایل در داخل برنامه از کدهای زیر میتوانید استفاده نمایید.  کد در سمت ui به شکل زیر است.

<!--
<af:panelFormLayout maxColumns="2" rows="1">
<af:forEach items="#{viewScope.inboxBean.attachment}" var="attach">
<af:commandImageLink icon="/images/attach.png" text="#{attach.name}" id="cl1">
<af:setActionListener from="#{attach.name}" to="#{viewScope.inboxBean.selectedFile}"/>
<af:fileDownloadActionListener filename="#{attach.name}" method="#{viewScope.inboxBean.downloadFile}"/>
</af:commandImageLink>
<af:spacer height="10" id="s1"/>
</af:forEach>
</af:panelFormLayout>
--><br />

در سمت manged bean که در اینجا downloadFile نام دارد کد زیر قراردارد. در کد زیر فرض شده است که فایلی که کاربر درخواست کرده است یک فایل zip است برای همین از zipfile استفاده شده است در غیر اینصورت به راحتی محتوای فایل خوانده شده و در IU نوشته میگردد.

public void downloadFile(FacesContext facesContext,<br />
OutputStream outputStream) {</p>
<p>Row current= JSFUtils.getCurrentRow("myFilesViewIterator");<br />
File zipFile=new File(current.getAttribute("filePath")+"\\"+current.getAttribute("fileName")); //current record...<br />
BeanUtils.logInfo(InboxBean.class.getName(),"downloadFile","going to view file: "+zipFile); //log the code...<br />
ZipInputStream zin=null;<br />
FileInputStream fin=null;<br />
try {</p>
<p>fin = new FileInputStream(zipFile);<br />
zin = new ZipInputStream(fin);<br />
ZipEntry entry = null; //read the zip file...<br />
attachment= new ArrayList();<br />
while ((entry = zin.getNextEntry()) != null) {</p>
<p>if (entry.getName().endsWith(selectedFile)) {</p>
<p>InputStream is= new BufferedInputStream(zin);</p>
<p>byte [] buff= new byte[2048];<br />
int len=-1;<br />
while((len=is.read(buff))!=-1){<br />
outputStream.write(buff,0,len); //write file content to the users to see the file<br />
//outputStream.flush();<br />
}</p>
<p>}</p>
<p>}<br />
BeanUtils.logInfo(InboxBean.class.getName(),"downloadFile","file downloaded successfully in inbox: "+zipFile);<br />
} catch (UnsupportedEncodingException uee) {<br />
// TODO: Add catch code<br />
uee.printStackTrace();<br />
BeanUtils.logError(InboxBean.class.getName(),"downloadFile",uee.getMessage());<br />
} catch (FileNotFoundException fnfe) {<br />
// TODO: Add catch code<br />
fnfe.printStackTrace();<br />
BeanUtils.logError(InboxBean.class.getName(),"downloadFile",fnfe.getMessage());<br />
} catch (IOException ioe) {<br />
// TODO: Add catch code<br />
ioe.printStackTrace();<br />
BeanUtils.logError(InboxBean.class.getName(),"downloadFile",ioe.getMessage());<br />
}finally{</p>
<p>if( fin==null){<br />
try{ fin.close();<br />
}catch(Exception e){<br />
System.err.println(e);<br />
}<br />
}<br />
} // Add event code here...<br />
}
خواندن بیشتر
royal visionنحوه استفاده از fileDownloadActionListener برای دانلود کردن فایل در داخل Oracle ADF (گرفتن پیوست و attachment)