`
seawenzhu
  • 浏览: 15727 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
最近访客 更多访客>>
社区版块
存档分类
最新评论

ADF 进度条的使用

ADF 
阅读更多

This post will teach you how to configure the ADF Progress Indicator component within a .jspx web page of your OFM 11g application.

Implementation

Step 1

Add the following code to your web.xml file:

<context-param>
    <description>Max size of a file that will be uploaded in ram (10B)</description>
    <param-name>org.apache.myfaces.trinidad.UPLOAD_MAX_MEMORY</param-name>
    <param-value>10</param-value>
  </context-param>
  <context-param>
    <description>Max size of a file that will be uploaded on HDD (100MB)</description>
    <param-name>org.apache.myfaces.trinidad.UPLOAD_MAX_DISK_SPACE</param-name>
    <param-value>104857600</param-value>
  </context-param>

UPLOAD_MAX_DISK_SPACE Context Parameter – by default this parameter is equal with 2 MB and it isn’t explicitly defined within web.xml.

Step 2

Open adfc-config.xml and define a new managed bean. The newly created bean should have it’s scope set to session and must extend org.apache.myfaces.trinidad.model.BoundedRangeModelabstract class.

BoundedRangeModel abstract class declares 2 methods:

getMaximum() – which will be used by the progress indicator to get the size of the file to be uploaded:

    public long getMaximum() {
        long result;
        long maxByte = getMaximumBytes();
        if (maxByte == 0)
            result = -1;
        else {
            result = maxByte;
        }
        return result;
    }

getValue() – which will be used by the progress indicator to set the size that remains to be uploaded (or the size that has been already uploaded):

    public long getValue() {
        long result;
        long availableByte = getMaximumBytes() - getAvailableBytes();
        if (availableByte == 0 || availableByte == getMaximumBytes())
            result = -1;
        else {
            result = availableByte;
        }
        return result;
    }

The uploading process is handled by the doUpload() method:

    public void doUpload(ActionEvent actionEvent) {
        if (file != null) {
            setSizeOfFile(file.getLength());
            Map<String, Object> atts = getPollid().getAttributes();
            InputStream is;
            OutputStream os;

            File destinationFile = new File(file.getFilename());
            try {
                is = file.getInputStream();
                os = new FileOutputStream(destinationFile);
                int data;
                setMaximumBytes(getSizeOfFile());
                while ((data = is.read()) != -1) {
                    os.write(data);
                    setAvailableBytes(is.available());
                }
                this.stopPoll();
                FacesContext fctx = FacesContext.getCurrentInstance();
                FacesMessage message =
                    new FacesMessage("Succesfully uploaded file: " + " " +
                                     file.getFilename() + ", containing " +
                                     getSizeOfFile() + " bytes.");
                message.setSeverity(FacesMessage.SEVERITY_INFO);
                fctx.addMessage(null, message);

                is.close();
                os.close();
            } catch (IOException e) {
                e.printStackTrace();

                FacesMessage message = new FacesMessage(e.getMessage());
                message.setSeverity(FacesMessage.SEVERITY_ERROR);
                FacesContext.getCurrentInstance().addMessage(null, message);
            }
        }
    }

In order to stop the poll, once the upload is done, we use the following method:

    public void stopPoll() {
        FacesContext fctx = FacesContext.getCurrentInstance();
        ExtendedRenderKitService service =
            Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
        service.addScript(fctx,
                          "AdfPage.PAGE.findComponent('" + getPollid().getClientId(fctx) +
                          "').setInterval(-1);");
    }

Step 3

In order to start the poll we shall use JavaScrip. The handlePoll function is listed below:

handlePoll = function (event) {
    //stops the event from propagating to the server side
    event.cancel();
    //gets the poll component, with respect to it's id, from the jspx page
    var poll = AdfPage.PAGE.findComponent('pollid');
    if (0 > poll.getInterval())
        //starts the poll and sets it's update interval to 1 second
        poll.setInterval(1000);
    else
        //stops the poll
        poll.setInterval( - 1);
}

Step 4

Now we shall configure the .jspx page as follows:

1. Register the JavaScript file with the jspx page by using the below line, inside af:document:

<af:resource type="javascript" source="/js/handlePoll.js"/>

2. Enable upload on the page:

<af:form id="f1" usesUpload="true">

3. Use af:inputFile to upload the file:

<af:inputFile label="File to upload:" id="if1"
                          value="#{MyProgressRangeModel.file}"
                          valueChangeListener="#{MyProgressRangeModel.uploadedFileChanged}"/>

4. Use af:progressIndicator in order to display the current status of the uploading process:

 <af:progressIndicator id="progressIndicator"
                                  value="#{MyProgressRangeModel}">
              <af:outputFormatted value="#{MyProgressRangeModel.percentageUploaded}% completed"
                                  id="of1"/>
            </af:progressIndicator>

Notice the value of the af:progressIndicator is set as the managed bean that we have implemented at step 2.
Also, although you cannot see it here (because is defined in the parent of the af:progressIndicator), we use a Partial Trigger, having it’s value equal to the id of the af:poll component , in order to update the af:progressIndicator.

5. af:poll component enables automatic update for af:progressIndicator:

<af:poll id="pollid" interval="-1"
                     binding="#{MyProgressRangeModel.pollid}"
                     clientComponent="true"/>

6. af:commandButton is used to invoke the doUpload() method and start the upload process:

<af:commandButton text="Run" id="cb2"
                              actionListener="#{MyProgressRangeModel.doUpload}">
              <af:clientListener method="handlePoll" type="click"/>

The af:clientListener is used to call the JavaScript method that will start the poll once the upload starts.

The look of the progress indicator component can be changed by changing the skin-family within thetrinidad-config.xml file or by implementing your custom component and use css to integrate it with the OFM application.  ADFProgressIndicator sample application uses fusion skin-family.

 

 

 

Running the application

Open ADFProgressIndicator OFM application in your JDevelopper IDE, navigate to Main.jspx page and run it – use Mozilla Firefox or Internet Explorer browsers; Google Chrome browser  represents a special case which will be discussed later in this post.

Hint: In order to set JDevelopper IDE default browser follow the steps below:

Open JDevelopper IDE -> Tools -> Preferences… -> Web Browser and Proxy (bottom part of the left facet) -> Browser Command Line:

After the application is successfully deployed you should see the following page:

Choose a file and press Run. A new panel box will be displayed, containing the progress indicator:

After the upload is done the progress indicator is hidden and the following info message is displayed:

Notice: In order for ADFProgressIndicator OFM application to run when using Google Chrome browser the following are required:

1. Create a new jspx page containing the af:progressIndicator and af:poll conponents.

2. Integrate the newly constructed page within the current page by using the iframe component:

 

<iframe src="NewlyConstructedPage.jspx"/>

 

 

分享到:
评论

相关推荐

    锁相环ADF5355的使用经验

    ### 锁相环ADF5355的使用经验与技巧 #### 一、概述 ADF5355是一款高性能的锁相环(PLL)频率合成器芯片,它结合了外部环路滤波器和外部参考频率,能够实现小数N分频或整数N分频的PLL频率合成。该芯片具有集成的...

    ADF检验MATLAB程序.zip_ADF单位根检验_ADF检测_MATLAB adf_adftest matlab_adf检验

    压缩包中的“ADF检验MATLAB程序.doc”文档可能详细介绍了如何使用MATLAB代码实现这些步骤,包括如何调用`adftest`函数,如何处理结果以及可能遇到的问题和解决方案。阅读这份文档将有助于深入理解和应用ADF检验。 ...

    ADF4351配置程序.zip_ADF4351_ADF4351程式_adf4350配置_adf4351 程序_adf4351配置

    **ADF4351配置程序** ADF4351是一款高性能、高精度的频率合成器,广泛应用于无线通信、测试设备、卫星接收等系统中。它具有宽范围的频率输出能力,可编程的分频器和倍频器设计,使得在不同应用中能够灵活调整输出...

    宽带PLL ADF41513(1)_ADF_acceptwcc_adf4360_ADF41513_ADf4360-7_

    标题中的“宽带PLL ADF41513(1)_ADF_acceptwcc_adf4360_ADF41513_ADf4360-7_”提及了两个关键器件:ADF41513和ADF4360-7。这两个都是高性能的频率合成器,在无线通信、测试设备以及各种信号处理应用中广泛使用。 ...

    ADF界面使用多皮肤 ADF刷新界面方法

    同时,使用ADF提供的调试工具可以方便地查看和调整皮肤效果。 通过上述知识点的学习和实践,开发者可以为ADF应用创建并实现多皮肤功能,提升用户体验,同时保持代码的可维护性和扩展性。在实际项目中,可以结合具体...

    ADF4351.rar_ADF4351_ADF4351锁相环例程_adf4351双路输出_adf4351辅助输出

    **ADF4351简介** ADF4351是一款高性能的射频(RF)频率合成器,由ADI公司设计生产,适用于多种无线通信系统。它采用先进的锁相环(PLL)技术,能够产生精确且可调的射频信号,频率范围广泛,正如描述中所提及的,...

    adf4159.rar_FMCW_adf4159

    压缩包内的“adf4159.c”文件很可能是一个C语言源代码,包含了使用ADF4159芯片的具体程序实现。通过分析这个源代码,我们可以深入理解如何配置ADF4159以实现1.5GHz的非FMCW输出,以及可能的寄存器设置和时序控制。...

    verilog配置ADF4355

    本教程将深入探讨如何使用硬件描述语言Verilog对ADF4355进行初始化配置。 首先,我们需要了解ADF4355的基本工作原理。ADF4355由一个锁相环(PLL)组成,可以产生精确的可调频率输出。它包括一个内置的压控振荡器...

    ADF41513 数据手册.PDF

    5. 单端参考输入:ADF41513 的参考输入端口为单端结构,方便用户使用。 6. 3.3 V 电源供应:ADF41513 的电源供应电压为 3.3 V,满足了大多数应用的需求。 7. 1.8 V 逻辑能力:ADF41513 具有 1.8 V 的逻辑能力,满足...

    adf4351的驱动代码、中文数据手册、相关论文讲解,adf4350中文手册,C,C++

    在这个压缩包中,包含的是ADF4351相关的关键资源,包括驱动代码、中文数据手册和相关论文讲解,这些都是理解和使用ADF4351所必需的知识点。 首先,让我们深入了解一下**ADF4351驱动代码**。驱动代码是与硬件设备...

    ADF5355 SPI程序

    本教程将深入探讨如何使用STM32微控制器通过SPI协议与ADF5355频率合成器进行通信。 **ADF5355简介** ADF5355是一款高性能的频率合成器,由Analog Devices公司生产,可提供广泛的频率范围和灵活的配置选项。它集成...

    adf4351配置模板及配置软件

    在本压缩包文件中,我们有两个关键文件,一个是配置软件"ADF435x_v4_5_0.exe",另一个是ADF4351的设置文本文件"ADF4351_settings.txt",以及一份简要的使用说明"readme.txt"。 首先,"ADF435x_v4_5_0.exe"是专为ADF...

    ADF4001/ADF4002的驱动代码(基于正点原子MINISTM32)

    本文将深入探讨基于正点原子MINISTM32平台的ADF4001/ADF4002驱动代码,这两个器件是高性能的锁相环(PLL)芯片,广泛应用于无线通信、射频系统以及频率合成等领域。 首先,我们要理解锁相环(Phase-Locked Loop,简称...

    ADF4351驱动程序

    MSP430以其高效能、低功耗和丰富的外设接口著称,非常适合在需要精确控制和节省能源的应用中使用。 **CCS(Code Composer Studio)**是TI提供的一个集成开发环境,用于编写、调试和优化基于TI微控制器和处理器的...

    STM32 ADF4351

    STM32与ADF4351结合使用,可以实现频率的精确控制和调节。STM32通过其强大的处理能力来配置和控制ADF4351的寄存器,从而产生所需的工作频率。锁相环是这种系统的核心部分,它能够锁定到外部参考信号,使输出频率与...

    adf文件转TIFF文件

    本话题主要涉及"adf文件转TIFF文件",这是一种将特定的数据格式转换为广泛使用的图像格式的过程。下面我们将深入探讨ADF(Arc/Info Binary Grid)文件和TIFF(Tagged Image File Format)文件,以及如何进行这种转换...

    adf检验_ADF检验_

    `code_section5_9.r`可能包含了具体实现ADF测试的函数或代码段,而`example1.r`可能是用来演示如何使用这些代码的实例。 在`example1.r`中,我们可能会看到如下步骤: 1. 加载必要的R包,如`tseries`或`urca`,它们...

    ADF使用javascript

    ### ADF 使用 JavaScript #### 引言 Oracle ADF(Application Development Framework)是一个基于 Java Server Faces 的组件框架,它利用 AJAX 和 JavaScript 技术来渲染客户端组件、实现丰富的组件功能、验证用户...

Global site tag (gtag.js) - Google Analytics