اوراکل

All posts tagged اوراکل

تولید فایل PDF با استفاده از اوراکل ADF

Generating PDF file or any sort of file is a common requirement among web portal applications. Generally, the requirement could be getting some data from a database and writing the same on to the file.

Oracle ADF (Application Development Framework) is a fast, simple and rich internet application development framework. Oracle ADF Faces Components are Ajax-enabled components that help in building a rich web user interface for Java EE applications.

When it comes to reports in Oracle ADF, the framework supports a feature called “Export to Excel.” The component supporting that feature isaf:exportCollectionActionListener. But unfortunately, even though it’s a sophisticated tool for designing and developing web applications, it doesn’t have a feature for generating dynamic PDF files. This post will help you understand how to generate PDF and download it on a command button click.

Requirements:

1. Generate some static data PDF file on a command button click.

2. Download the same file to the specified location.

Process:

1. Create a new project.

Here we use Jdeveloper 11g Release (11.1.1.3.0) version. In order to create a new project click on option File > New option in the pane.  The dialog appears as below and select Fusion Web Application (ADF).

PDF20using20Oracle20ADF201-resized-600.jpg

Once you create a new Application, JDeveloper creates you two projects as shown in the below screen shot.

PDF20using20Oracle20ADF202-resized-600.jpg

2. Create a UI Page:

Our goal is to generate a PDF file when clicked on a command button and download the generated file. Now to have that provision we need a UI page with a command button. So we shall create a UI page with simple Command Button.

Step 1: Right on View Controller project, select New option and then JSF page under JSF category.

PDF20using20Oracle20ADF203-resized-600.jpg

Step 2: create a Jspx page as shown below.

PDF20using20Oracle20ADF204-resized-600.jpg

Note: Make sure you check Create as XML Document option.

Step 3: Once you are done with creating the Jspx file, drag and drop the Panel Box and Command Button from the Common Components palate. The page looks like this:

PDF20using20Oracle20ADF205-resized-600.jpg

Step 4: Drag and drop fileDownloadActionListener on to the command button from the Component Palate.  And change properties as shown in the below screen.

PDF20using20Oracle20ADF206-resized-600.jpg

Properties:

PDF20using20Oracle20ADF207-resized-600.jpg

Where Filename is the output file name and Method is the Bean method call when clicked on button.

Source: 

PDF20using20Oracle20ADF208-resized-600.jpg

3. Create a Bean classes:

To generate a PDF and download the file we need some Java program which runs at the server side and provides the desired results. To make this happen we need a Jar file called IText. In this sample, we used ITextPdf-5.1.3.jar.

Step 1: In order to reflect the classes in the jar file which helps in generating PDF, we need to import the jar file. To import jar file, Click on ViewController > ProjectProperties > Libraries and Classpath > Add Jar/ Directory and import from the location as shown in the below screen shot.

PDF20using20Oracle20ADF209-resized-600.jpg

Step2: Create a two bean (java) classes, where one class contains all the Accessors and another class contains the PDF generation and Downloading methods.

PDF20using20Oracle20ADF2010-resized-600.jpg

4. Create download the generated file methods.

PDFGeneratorBean.java source code:

package winne.filegeneration.view.backing;</p>
<p>import java.io.File;</p>
<p>import java.io.FileInputStream;</p>
<p>import java.io.IOException;</p>
<p>import java.io.OutputStream;</p>
<p>import javax.faces.application.FacesMessage;</p>
<p>import javax.faces.context.ExternalContext;</p>
<p>import javax.faces.context.FacesContext;</p>
<p>import javax.servlet.ServletContext;</p>
<p>import javax.servlet.http.HttpServletResponse;</p>
<p>import oracle.adf.view.rich.component.rich.RichDocument;</p>
<p>import oracle.adf.view.rich.component.rich.RichForm;</p>
<p>import oracle.adf.view.rich.component.rich.layout.RichPanelBox;</p>
<p>import oracle.adf.view.rich.component.rich.layout.RichPanelGroupLayout;</p>
<p>import oracle.adf.view.rich.component.rich.layout.RichPanelStretchLayout;</p>
<p>import oracle.adf.view.rich.component.rich.nav.RichCommandButton;</p>
<p>public class PDFGeneratorBean {</p>
<p>private RichPanelStretchLayout psl1;</p>
<p>private RichForm f1;</p>
<p>private RichDocument d1;</p>
<p>private RichCommandButton cb1;</p>
<p>private RichPanelGroupLayout pgl1;</p>
<p>private RichPanelBox pb1;</p>
<p>public void setPsl1(RichPanelStretchLayout psl1) {</p>
<p>this.psl1 = psl1;</p>
<p>}</p>
<p>public RichPanelStretchLayout getPsl1() {</p>
<p>return psl1;</p>
<p>}</p>
<p>public void setF1(RichForm f1) {</p>
<p>this.f1 = f1;</p>
<p>}</p>
<p>public RichForm getF1() {</p>
<p>return f1;</p>
<p>}</p>
<p>public void setD1(RichDocument d1) {</p>
<p>this.d1 = d1;</p>
<p>}</p>
<p>public RichDocument getD1() {</p>
<p>return d1;</p>
<p>}</p>
<p>public void setCb1(RichCommandButton cb1) {</p>
<p>this.cb1 = cb1;</p>
<p>}</p>
<p>public RichCommandButton getCb1() {</p>
<p>return cb1;</p>
<p>}</p>
<p>public void setPgl1(RichPanelGroupLayout pgl1) {</p>
<p>this.pgl1 = pgl1;</p>
<p>}</p>
<p>public RichPanelGroupLayout getPgl1() {</p>
<p>return pgl1;</p>
<p>}</p>
<p>public void setPb1(RichPanelBox pb1) {</p>
<p>this.pb1 = pb1;</p>
<p>}</p>
<p>public RichPanelBox getPb1() {</p>
<p>return pb1;</p>
<p>}</p>
<p>public void addMessage(FacesMessage.Severity type, String message) {</p>
<p>FacesContext fctx = FacesContext.getCurrentInstance();</p>
<p>FacesMessage fm = new FacesMessage(type, message, null);</p>
<p>fctx.addMessage(null, fm);</p>
<p>}</p>
<p>}</p>
<p>DownloadFileBean.java source code:</p>
<p>package winne.filegeneration.view.backing;</p>
<p>import com.itextpdf.text.BaseColor;</p>
<p>import com.itextpdf.text.Document;</p>
<p>import com.itextpdf.text.DocumentException;</p>
<p>import com.itextpdf.text.Font;</p>
<p>import com.itextpdf.text.Paragraph;</p>
<p>import com.itextpdf.text.pdf.PdfWriter;</p>
<p>import java.io.File;</p>
<p>import java.io.FileInputStream;</p>
<p>import java.io.FileOutputStream;</p>
<p>import java.text.SimpleDateFormat;</p>
<p>import java.util.Date;</p>
<p>import javax.faces.context.ExternalContext;</p>
<p>import javax.faces.context.FacesContext;</p>
<p>import javax.servlet.ServletContext;</p>
<p>import javax.servlet.http.HttpServletResponse;</p>
<p>import oracle.adf.model.BindingContainer;</p>
<p>import oracle.adf.model.BindingContext;</p>
<p>public class DownloadFileBean {</p>
<p>public DownloadFileBean() {</p>
<p>}</p>
<p>private static String FILE = “c:/temp/Salary_Breakdown_June.pdf”;</p>
<p>private static Font catFont =</p>
<p>new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);</p>
<p>private static Font redFont =</p>
<p>new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED);</p>
<p>private static Font subFont =</p>
<p>new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD);</p>
<p>private static Font smallBold =</p>
<p>new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);</p>
<p>private BindingContainer bindings;</p>
<p>public void generatePDF(FacesContext facesContext,</p>
<p>java.io.OutputStream outputStream) {</p>
<p>this.generatePDFFile(facesContext, outputStream); // Generate PDF File</p>
<p>this.downloadPDF(facesContext, outputStream); // Download PDF File</p>
<p>}</p>
<p>private void downloadPDF(FacesContext facesContext,</p>
<p>java.io.OutputStream outputStream) {</p>
<p>try {</p>
<p>facesContext = facesContext.getCurrentInstance();</p>
<p>ServletContext context =</p>
<p>(ServletContext)facesContext.getExternalContext().getContext();</p>
<p>ExternalContext ctx = facesContext.getExternalContext();</p>
<p>HttpServletResponse res = (HttpServletResponse)ctx.getResponse();</p>
<p>res.setContentType(“application/pdf”);</p>
<p>System.out.println(context.getRealPath(“/”));</p>
<p>File file = new File(FILE);</p>
<p>FileInputStream fdownload;</p>
<p>byte[] b;</p>
<p>fdownload = new FileInputStream(file);</p>
<p>int n;</p>
<p>while ((n = fdownload.available()) &gt; 0) {</p>
<p>b = new byte[n];</p>
<p>int result = fdownload.read(b);</p>
<p>outputStream.write(b, 0, b.length);</p>
<p>if (result == -1)</p>
<p>break;</p>
<p>}</p>
<p>outputStream.flush();</p>
<p>} catch (Exception e) {</p>
<p>e.printStackTrace();</p>
<p>}</p>
<p>}</p>
<p>private void generatePDFFile(FacesContext facesContext,</p>
<p>java.io.OutputStream outputStream) {</p>
<p>try {</p>
<p>System.out.println(“In Generate PDF…………….”);</p>
<p>Document document = new Document();</p>
<p>PdfWriter.getInstance(document, new FileOutputStream(FILE));</p>
<p>document.open();</p>
<p>addMetaData(document);</p>
<p>addTitlePage(document);</p>
<p>//addContent(document);</p>
<p>document.close();</p>
<p>System.out.println(“End of PDF………………….”);</p>
<p>facesContext = facesContext.getCurrentInstance();</p>
<p>ServletContext context =</p>
<p>(ServletContext)facesContext.getExternalContext().getContext();</p>
<p>System.out.println(context.getRealPath(“/”));</p>
<p>File file = new File(FILE);</p>
<p>FileInputStream fdownload;</p>
<p>byte[] b;</p>
<p>System.out.println(file.getCanonicalPath());</p>
<p>System.out.println(file.getAbsolutePath());</p>
<p>fdownload = new FileInputStream(file);</p>
<p>int n;</p>
<p>while ((n = fdownload.available()) &gt; 0) {</p>
<p>b = new byte[n];</p>
<p>int result = fdownload.read(b);</p>
<p>outputStream.write(b, 0, b.length);</p>
<p>if (result == -1)</p>
<p>break;</p>
<p>}</p>
<p>outputStream.flush();</p>
<p>} catch (Exception e) {</p>
<p>e.printStackTrace();</p>
<p>}</p>
<p>// / return null;</p>
<p>// Add event code here…</p>
<p>}</p>
<p>// iText allows to add metadata to the PDF which can be viewed in your Adobe</p>
<p>// Reader</p>
<p>// under File -&gt; Properties</p>
<p>private static void addMetaData(Document document) {</p>
<p>document.addTitle(“My first PDF”);</p>
<p>document.addSubject(“Using iText”);</p>
<p>document.addKeywords(“Java, PDF, iText”);</p>
<p>document.addAuthor(“Lars Vogel”);</p>
<p>document.addCreator(“Lars Vogel”);</p>
<p>}</p>
<p>private static void addTitlePage(Document document) throws DocumentException {</p>
<p>Date month = new Date();</p>
<p>SimpleDateFormat currentMonth = new SimpleDateFormat(“MMMM”);</p>
<p>Paragraph preface = new Paragraph();</p>
<p>// We add one empty line</p>
<p>addEmptyLine(preface, 1);</p>
<p>// Lets write a big header</p>
<p>preface.add(new Paragraph(“Salary Structure for Month – ” +</p>
<p>currentMonth.format(month), catFont));</p>
<p>document.add(preface);</p>
<p>// Start a new page</p>
<p>// document.newPage();</p>
<p>}</p>
<p>private static void addEmptyLine(Paragraph paragraph, int number) {</p>
<p>for (int i = 0; i &lt; number; i++) {</p>
<p>paragraph.add(new Paragraph(” “));</p>
<p>}</p>
<p>}</p>
<p>public static oracle.binding.BindingContainer getBindings() {</p>
<p>return BindingContext.getCurrent().getCurrentBindingsEntry();</p>
<p>}

5Output.

PDF20using20Oracle20ADF2011-resized-600.jpg

Note: The dialog box pop up appearance depends on browser settings. Make sure that you have “Ask before download” option checked in your browser settings.

Hopefully this post is helpful!

Do you have questions or need clarification? Let me know what you think – or have anything to add to this topic. Post in the comments section or click the button, below, and I’ll get back to you!

Need help? Talk to an expert now!

References:
http://www.vogella.com/articles/JavaPDF/article.html
http://hasamali.blogspot.in/2011/09/download-file-in-oracle-adf-gui.html

خواندن بیشتر
royal visionتولید فایل PDF با استفاده از اوراکل ADF

نحوه اتصال وب لاجیک به سایتهایی که SSL هستند

سلام در این بلاگ قصد دارم نحوه اتصال وب لاجیک به سایتهایی که SSL هستند را توضیح بدهم.
اگر قصد دارید که مثلاً در داخل یک برنامه مانند JSF یا ADF به وب سایت بانک پاسارگاد متصل شوید تا از نتیجه تراکنش مطلع گردید با یک HTTPClient ساده نمیتوانید این موضوع را حل نمایید زیرا وب لاجیک امکان اتصال را به شما نمیدهد برای این منظور باید فایل crt وب سایت امن را در داخل وب لاجیک وارد نمایید تا یک لینک trust بین سرور ها ایجاد گردد.
مرحله اول گرفتن فایل crt از وب سابت میباشد در تصاویر زیر من نحوه گرفتن فایل را از یک وب سایت نمونه مانند سایت بانک پاسارگاد نمایش داده ام.
مراحل زیر را به ترتیب انجام دهید تا فایل certificate دانلود گردد برای این منظور من از Firefox استفاده کرده ام.
سایت بانک پاسارگاد برای چک کردن وضعیت پرداخت: https://fanapepay.bpi.ir/checktransactionresult.aspx

پس از ذخیره فایل به مسیر jdk مربوط به middleware home بروید در کامپیوتر من این مسیر معادل D:\Oracle\Middleware\jdk160_24\bin
و فایل گرفته شده pasargad.pem را در آن فلدر ذخیره نمایید.
سپس به command prompt رفته و کدهای زیر را به ترتیب اجرا نمایید.

در این مرحله کلمه عبور برابر است با:DemoTrustKeyStorePassPhrase

در این مرحله برای سوال پرسیده شده کلمه yes را وارد نمایید.

حال وب لاجیک به راحتی میتواند به سابت SSL متصل گردد.
کد ارسال و نمونه برنامه در پیوست وجود دارد.

نمونه کد نوشته شده در managed bean برای ارسال کد به سایت پاسارگاد و خواندن جواب بازگشت

package view;<br />
import java.io.BufferedReader;<br />
import java.io.DataOutputStream;<br />
import java.io.InputStreamReader;<br />
import java.net.HttpURLConnection;<br />
import java.net.URL;</p>
<p>import java.security.cert.X509Certificate;</p>
<p>import javax.net.ssl.HttpsURLConnection;<br />
import javax.net.ssl.SSLContext;<br />
import javax.net.ssl.TrustManager;<br />
import javax.net.ssl.X509TrustManager;</p>
<p>public class MyClass {</p>
<p>private final String USER_AGENT = "Mozilla/5.0";</p>
<p>public static void main(String[] args) throws Exception {</p>
<p>MyClass http = new MyClass();</p>
<p>System.out.println("\nTesting 1 - Send Https POST request");<br />
http.postAction();<br />
System.out.println("\nTesting 2 - After Send Https POST request");</p>
<p>}</p>
<p>public String postAction() throws Exception {<br />
// Create a trust manager that does not validate certificate chains<br />
TrustManager[] trustAllCerts = new TrustManager[]{<br />
new X509TrustManager() {<br />
public java.security.cert.X509Certificate[] getAcceptedIssuers() {<br />
return null;<br />
}<br />
public void checkClientTrusted(<br />
java.security.cert.X509Certificate[] certs, String authType) {<br />
}<br />
public void checkServerTrusted(<br />
java.security.cert.X509Certificate[] certs, String authType) {<br />
}<br />
}<br />
};</p>
<p>// Install the all-trusting trust manager<br />
try {<br />
SSLContext sc = SSLContext.getInstance("SSL");<br />
sc.init(null, trustAllCerts, new java.security.SecureRandom());<br />
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());<br />
} catch (Exception e) {<br />
System.out.println(e.getMessage());<br />
e.printStackTrace();<br />
}<br />
String url = "https://fanapepay.bpi.ir/checktransactionresult.aspx";<br />
URL obj = new URL(url);<br />
weblogic.net.http.SOAPHttpsURLConnection con = (weblogic.net.http.SOAPHttpsURLConnection) obj.openConnection();</p>
<p>//add reuqest header<br />
con.setRequestMethod("POST");<br />
con.setRequestProperty("User-Agent", USER_AGENT);<br />
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");</p>
<p>String urlParameters ="invoiceUID=6352140483062587301";</p>
<p>// Send post request<br />
con.setDoOutput(true);<br />
DataOutputStream wr = new DataOutputStream(con.getOutputStream());<br />
wr.writeBytes(urlParameters);<br />
wr.flush();<br />
wr.close();</p>
<p>int responseCode = con.getResponseCode();<br />
System.out.println("\nSending 'POST' request to URL : " + url);<br />
System.out.println("Post parameters : " + urlParameters);<br />
System.out.println("Response Code : " + responseCode);</p>
<p>BufferedReader in = new BufferedReader(<br />
new InputStreamReader(con.getInputStream()));<br />
String inputLine;<br />
StringBuffer response = new StringBuffer();</p>
<p>while ((inputLine = in.readLine()) != null) {<br />
response.append(inputLine);<br />
}<br />
in.close();</p>
<p>//print result<br />
System.out.println(response.toString());<br />
return null;<br />
}<br />
}

firefox-step1.png

%D9%84%DB%8C%D8%B3%D8%AA %D8%B3%D9%88%D8%A7%D9%84%D8%A7%D8%AA - نحوه اتصال وب لاجیک به سایتهایی که SSL هستند

firefox-step2.png

%D9%84%DB%8C%D8%B3%D8%AA %D8%B3%D9%88%D8%A7%D9%84%D8%A7%D8%AA - نحوه اتصال وب لاجیک به سایتهایی که SSL هستند

%D9%84%DB%8C%D8%B3%D8%AA %D8%B3%D9%88%D8%A7%D9%84%D8%A7%D8%AA - نحوه اتصال وب لاجیک به سایتهایی که SSL هستند

%D9%84%DB%8C%D8%B3%D8%AA %D8%B3%D9%88%D8%A7%D9%84%D8%A7%D8%AA - نحوه اتصال وب لاجیک به سایتهایی که SSL هستند

%D9%84%DB%8C%D8%B3%D8%AA %D8%B3%D9%88%D8%A7%D9%84%D8%A7%D8%AA - نحوه اتصال وب لاجیک به سایتهایی که SSL هستند

%D9%84%DB%8C%D8%B3%D8%AA %D8%B3%D9%88%D8%A7%D9%84%D8%A7%D8%AA - نحوه اتصال وب لاجیک به سایتهایی که SSL هستند

%D9%84%DB%8C%D8%B3%D8%AA %D8%B3%D9%88%D8%A7%D9%84%D8%A7%D8%AA - نحوه اتصال وب لاجیک به سایتهایی که SSL هستند

خواندن بیشتر
royal visionنحوه اتصال وب لاجیک به سایتهایی که SSL هستند

ساخت فایل 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)