ADF rich faces offer a nice and easy feature to stream data to the client (e.g. Excel) using the af:exportCollectionActionListener or af:fileDownloadActionListener component. Both of the components get
the output stream from the response, so the application an add the data.
One problem is that the two components fire before the application has a chance to validate other data on the page or do some other needed work.
To overcome this shortcoming you can implement the trick I’m outlining in this blog. The idea is to use a normal af:commandbutton or af:commandToolbarButton on the page which calls an actionListener in a bean. In there you can validate other page data or do
some other stuff in the model, and then queue an event inside the bean method to call another invisible button on the page which has the af:exportCollectionActionListener attached.
As it turned out (thanks Jiandong Xin for pointing it out), there is a problem if the button we queue the action event to has a client behavior tag attached. This is the case for af:exportCollectionActionListener
or af:fileDownloadActionListener. These tags don’t work properly if we only queue an event to the parent button. As Jobinesh pointed out in hisblogwe
need to insert a JavaScript function into the page which handles the event queuing from JavaScript and call it from the bean. This way we are able to set the needed parameters (e.g. not to wait for a response).
Now lets implement this: Lets start with a toolbar button which resides on a panel collection holding the table we want to export. The button has a binding to the bean (binding=”#{exportBean.exportCollectionButton}”)
to make it easier to call it from the bean. If you don’t like to bind the button to the bean, you can search for the component by name inside the action listener we implement below. The page contains the custom handler (customHandler(event)) which we call
from the bean method. This handler then queues the event to activate the button which starts the file download. The connection between the customHander and hte commandToolbarButton is the ID of the commandToolbarButton (“ctb1″). You have to change this if
your button has a different ID.
-
<af:resourcetype="javascript">
-
functioncustomHandler(event){
-
varexportCmd=AdfPage.PAGE.findComponentByAbsoluteId("ctb1");
-
varactionEvent=newAdfActionEvent(exportCmd);
-
actionEvent.forceFullSubmit();
-
actionEvent.noResponseExpected();
-
actionEvent.queue();
-
}
-
</af:resource>
-
<af:panelCollectionid="pc1">
-
<f:facetname="menus"/>
-
<f:facetname="toolbar">
-
<af:toolbarid="t2"binding="#{exportBean.toolbar}">
-
<af:commandToolbarButtontext="Export..."id="ctb1"
-
binding="#{exportBean.exportCollectionButton}"
-
visible="false">
-
<af:exportCollectionActionListenertype="excelHTML"exportedId="t1"
-
title="Export"/>
-
</af:commandToolbarButton>
-
...
The vital part is that the visible property is set to “false”, so that the button will not show up on the page, but is fully functional. Somewhere else on the page (or even on the same toolbar) we have
an with an action listener pointing to a bean method (exportBean in the sample). This button is visible and used to initiate the export.
-
...
-
<af:commandButtontext="exportviabean"id="cb8"
-
actionListener="#{exportBean.exportprgActionListener}"/>
-
...
The exportBean actionListener looks like this
-
-
privateRichCommandToolbarButtonexportCollectionButton;
-
...
-
publicvoidexportprgActionListener(ActionEventactionEvent){
-
-
-
-
FacesContextcontext=FacesContext.getCurrentInstance();
-
ExtendedRenderKitServiceerks=
-
Service.getService(context.getRenderKit(),ExtendedRenderKitService.class);
-
erks.addScript(context,"customHandler();");
-
}
In the action listener above you can validate other data on the page or call service methods in your application module before starting the export, or cancel the export if you like. The export runs as if you click
the af:exportCollectionActionListener directly.
You can download a sample workspaceBlogFileDownLoadTest.zip
After download remove the ‘.doc’ suffix!
分享到:
相关推荐
jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求。该插件捆绑了一套有用的验证方法,包括 URL 和电子邮件验证,同时提供了一个用来...
validate_before_handin
var validate = require ( '@smallwins/validate' )function hi ( params , callback ) { var schema = { 'name' : { required : true , type : Object } , 'name.first' : { required : true , type : String } , ...
#Express validate.js 验证框架的中间件包装器 ##安装 $ npm install express-validate.js ##例子 var validate = require ( 'express-validate.js' ) , express = require ( 'express' ) ; express ( ) ....
数据--验证--货币 Perl 模块验证字符串是否是正确的货币
validate自动校验源码 博文链接:https://jianglanlan.iteye.com/blog/1856659
为什么? 如果在编辑配置时收到验证错误,则直到下一个Dependabot运行时,您才知道是否存在问题。 即使周期很长并且未设置警报,也可能会在更晚的时间检测到。... - uses : marocchino/validate-dependabot@v1
jquery.validate.1.9.0.min.js jquery.validate.1.12.0.min.js jquery.validate.1.13.1.min.js jquery.validate.1.16.0.min.js jquery.validate.1.14.0.min.js jquery.validate.1.15.1.min.js jquery.validate....
用法使用npm install validate-data安装库const validate = require ( 'validate-data' ) ;// Validation rules const rules = { required : "email name age" , email : "email" , string : "email name" , number ...
非常感谢你中文说明请查看 转到文档godoc的godoc 适用于github的godoc 验证结构使用结构的validate标签,您可以快速验证结构数据。 提供扩展功能: 该结构可以实现三个接口方法,可以方便地进行一些自定义: 创建...
Validate.js-快速方法 这是使用JavaScript编写HTML数据属性来验证表单的简便方法的示例。 此代码使用 , , 和。 它还具有Internet Explorer的占位符备用。 如所示,此代码可用作RequireJS模块。 要求 这些是您的...
formchack和validate.js实时验证:http://blog.csdn.net/libin_1/article/details/50705331
npm install validate-email-dns 用法 var co = require ( 'co' ) ; var validate = require ( 'validate-email-dns' ) ; co . wrap ( validate ) ( 'test@example.com' ) . then ( function ( correct ) { if ( ...
composer require "payfast/laravel-validate-pwned-password":"^1.0" 对于Laravel(<5> register ( 'PayFast\\Providers\\PwnedPasswordServiceProvider' ); 用法 现在,使用Laravel验证时,您可以将新规则...
$ npm i egg-validate --save 用法 // config/plugin.js exports . validate = { enable : true , package : 'egg-validate' , } ; 构型 egg-validate支持所有参数的配置,检查以获取更多信息。 // config/config...
validate-json-schema-form 使用验证表单。 安装 $ npm install validate-json-schema-form 用法 < form id =" signup-form " > < input name =" username " type =" text " placeholder =" username " ...
This is a book introducing different kinds of surrogate model, including other mathematical knowledge to validate the accuracy of surrogates.It also contains methods about sampling. The book also ...
- 演示A. 复制或 git pull 这个仓库到 cgi 目录。 更正 ./form/config.yml 以访问数据库。... 数据表:长度菜单:10 下一部分调整验证码。 验证码:长度:4 到期:300 # 可选。 默认 300 宽度:25 # 可选。...
验证器 Macros 1.1 custom派生可简化由和验证程序启发的结构验证。 支持的最低版本是Rust 1.42。...#[derive(Debug, Validate, Deserialize)]struct SignupData { #[validate(email)] mail: String , #[validate(phone)
The Data Binding Validator makes it easy and quick to validate fields in forms using data binding framework. Download Step 1: Add it in your root build.gradle at the end of repositories: allprojects {...