`
pengtyao
  • 浏览: 398421 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

a4j:jsFunction & a4j:actionparam

阅读更多
这次JSF的项目中遇到一种特殊情况,在一个CommandLink的动作中先激活Manage Bean中的功能代码段,然后再执行一段脚本代码,查看了RichFaces的手册后决定使用a4j:jsFunction来实现,实现过程如下:

首先需要在页面中声明两个脚本函数:

......

<script type="text/javascript">
? function showContent(){
? ?alert("aaa"); ??
? }


? function [color=red]callScript[/color](){
? }
</script>

......


其中showContent是真正想执行的脚本代码,callScript没有实际用途,只是用来激活a4j:jsFunction功能,

CommandLink调用脚本callScript自动激活a4j:jsFunction:

......
<h:commandLink onmouseup="[color=red]callScript[/color]()"
? value="Test"/>


......

接下来就该添加a4j:jsFunction标签:

......

<a4j:jsFunction name="[color=red]callScript[/color]" action="#{testBean.unzipMmsZipFile}"
? oncomplete="showContent()" />

......

其中testBean为后台Manage Bean的实例,红色标注的部分必须相同,要不无法激活a4j:jsFunction部分的功能,有些人可能会想既然callScript脚本没有实际意义,为什么还要添加这段无用代码,直接把CommandLink和a4j:jsFunction中的callScript换成showContent不就行了,这样照样可以激活a4j:jsFunction的功能,如果只是为了让a4j:jsFunction触发Manage Bean中的某个事件的话这样确实可行,但是在本例中会出现问题,导致a4j:jsFunction中的oncomplete不能正常执行,所以在这里声明了一个无用的脚本函数,还有一点需要注意,在本例中最好使用action来激活Manage Bean中的功能代码,而不要使用actionListener,在我的测试中,利用actionListener能够正常激活Bean中的功能代码,但是有时会出现a4j:jsFunction中的oncomplete无法正常执行的情况,所有还是建议使用action

转自:http://dev.firnow.com/course/1_web/javascript/jsjs/2008828/138149.html

**********************************************************************************
http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/a4j_actionparam.html
**********************************************************************************
6.1.2.2. Details of Usage

The <a4j:actionparam> component has 3 main attributes:

    *

      "name" defines a name of this parameter
    *

      "value" defines initial value of this parameter or a value binding
    *

      "assignTo" defines updatable bean property. This property will be updated if the parent command component performs an actionEvent. The update occurs in the same phase as the actionEvent is processed (INVOKE_APPLICATION, PROCESS_VALIDATIONS, or APPLY_REQUEST_VALUES, depending on the values of the "immediate" and "bypassUpdates" attributes).

Example:


...

<h:form id="form">

    <a4j:commandButton value="Set Name to Alex" reRender="rep">

        <a4j:actionparam name="username" value="Alex" assignTo="#{actionparamBean.name}"/>

    </a4j:commandButton>

    <br/>

    <h:outputText id="rep" value="Name: #{actionparamBean.name}"/>

</h:form>

...


There is a managed bean:

...

public class ActionparamBean {

    private String name = "John";


    public String getName() {

        return name;

    }


    public void setName(String name) {

        this.name = name;

    }

}

...


You can use <a4j:actionparam> not only with Ajax components, but with non-ajax command component also. This feature allows to update model values without invoking even a single line of Java code on the server side. The usage of this feature you can find at ActionParameter Usage page of RichFaces LiveDemo.

If you need to convert the value before the "Update Model" phase you can specify the converter in the "converter" attribute.

Note:

The property is assigned with a parameter value on the "Update Model" phase. Therefore if the validation of the form is failed, this phase will be skipped and the property won't be updated.

It is possible to use JavaScript expression or function in the "value" attribute. In this case the "noEscape" attribute should be set to "true". The result of this JavaScript invocation is sent to the server as a value of <a4j:actionparam> .
分享到:
评论

相关推荐

    ajax4jsf中文教程

    a4j:actionparam a4j:status a4j:loadBundle a4j:mediaOutput 5. Ajax4jsf内建的换肤功能 6. 技术要求 支持的java版本 支持的 JavaServer Faces 实现 支持的服务器 支持的浏览器 7. 附加的设置 Web程序描述...

    a4j框架应用实例简介

    1. **异步通信**:A4J支持在后台与服务器进行异步数据交换,这意味着用户可以在不刷新整个页面的情况下更新特定部分。这种技术显著提高了Web应用的性能和用户友好性。 2. **事件驱动**:A4J利用JSF的事件模型,允许...

    ajax 4jsf用户指南中文版

    a4j:actionparam a4j:status a4j:loadBundle a4j:mediaOutput 5. Ajax4jsf内建的换肤功能 6. 技术要求 支持的 java版本 支持的 JavaServer Faces 实现 支持的服务器 支持的浏览器 7. 附加的设置 Web程序...

    关于rich:fileUpload和a4j:mediaOutput的使用

    在本文中,我们将深入探讨`rich:fileUpload`和`a4j:mediaOutput`这两个组件在实际开发中的使用,特别是在处理文件上传和媒体输出时的关键知识点。它们都是RichFaces库的一部分,这是一个强大的JavaServer Faces (JSF...

    <h:selectOneMenu>与<a4j:support>的集合运用(JSF)

    在JSF(JavaServer Faces)框架中,`&lt;h:selectOneMenu&gt;` 是一个用于创建下拉选择框的组件,而 `&lt;a4j:support&gt;` 是RichFaces库提供的一种Ajax支持的标签,它允许我们实现页面的部分更新,提高用户体验。这篇博客文章...

    a4j 指南

    3. **请求和响应处理**:A4J使用`&lt;a4j:jsFunction&gt;`来定义JavaScript函数,这些函数可以触发AJAX请求,并处理服务器返回的响应。 4. **区域更新**:A4J提供了`&lt;a4j:region&gt;`标签,可以定义页面上的特定区域,当AJAX...

    A4J ajax4jsf中文指南 chm

    1. **实时更新**:A4J允许部分页面在不刷新整个页面的情况下更新,提高用户体验。 2. **事件驱动**:它使用JSF事件模型来触发AJAX请求,使得处理用户交互更为方便。 3. **可配置的异步行为**:开发者可以定义何时...

    Ajax4JSF用户指南

    7. `a4j:actionparam`:传递参数到Ajax动作。 8. `a4j:status`:管理Ajax请求的状态指示。 9. `a4j:loadBundle`:动态加载资源包。 10. `a4j:mediaOutput`:处理媒体输出。 Ajax4JSF还提供了内建的皮肤功能,允许...

    RichFaces说明文档.doc

    作用:&lt;a4j:ajaxListener&gt; 能够监听用户的交互事件,例如,点击按钮、选择下拉菜单等,并执行相应的服务器端逻辑。 编写事件监听类:&lt;a4j:ajaxListener&gt; 需要编写事件监听类,用于处理用户的交互事件。 编写页面:...

    ajax4jsf常用标签的使用借鉴.pdf

    在本文中,我们将探讨Ajax4JSF中的几个常用标签,包括`a4j:ajaxListener`、`a4j:region`和`a4j:page`,以及它们的相关属性和使用场景。 1. `a4j:ajaxListener`: 这个标签用于注册一个方法作为Ajax事件的监听器。...

    ajax4jsf 用户指南

    - `a4j:actionparam`:传递参数到动作方法。 - `a4j:status`:管理 AJAX 请求状态。 - `a4j:loadBundle`:加载资源包。 - `a4j:mediaOutput`:处理媒体输出。 每个组件都有特定的属性,如 `attributes` 列表中所...

    ajax4jsf中文用户指南

    **决定发送什么**:你可以控制哪些数据随请求一起发送,比如通过`a4j:actionparam`传递参数,或者更新整个组件树的一部分。 **决定改变什么**:在服务器端处理完请求后,Ajax4JSF可以更新页面上的特定区域,而无需...

    A4j 原创小案例+Spring+hibernate

    【标题】:“A4j 原创小案例+Spring+Hibernate”是一个综合性的IT学习资源,涵盖了多个关键的技术框架,旨在帮助用户理解和实践这些技术的整合应用。 【描述】:“个人做的 小例子 A4j Myfaces JSF Spring ...

    ajax4jsf 例子

    5. **客户端更新**:a4j.js脚本接收响应,更新页面中的指定区域。 6. **用户反馈**:用户看到页面相应部分的变化,而无需等待整个页面的重新加载。 ### 5. 示例代码 ```html &lt;%@ taglib uri="http://richfaces.org...

    Usage of A4J.Usage of A4J.Usage of A4J.

    Usage of A4J.Usage of A4J.Usage of A4J.

    A4纸打印尺子(1:1).pdf

    可以用A4 1:1打印,可以偶尔应急使用, pdf格式,下载打印后可以当尺子用.测过一次,误差在2毫米内..

    ajax4jsf.zip

    例如,A4J提供了`&lt;a4j:support&gt;`和`&lt;a4j:ajax&gt;`等标签,这些标签可以附加到JSF组件上,定义触发Ajax请求的事件和处理响应的方式。 在使用Ajax4JSF时,开发者可以利用其核心组件,如`&lt;a4j:commandButton&gt;`和`&lt;a4j:...

    JSF结合A4J技术的二级联动

    JSF配用A4J在jsp中进行的二级联动使用方法。

    music.note.height:从Midi &lt;->音符名称&lt;->频率转换的微小库

    fromMidi ( 69 ) // =&gt; 'A4' // write it to the console console . log ( name ) // =&gt; prints 'A4' // give it to your synth note . toFreq ( name ) // =&gt; 440 这是一部分 特征 音符名称为midi和midi音符名称...

    ajax4jsf使用手册

    - **Ajax 组件**:Ajax4JSF 提供了一系列预定义的UI组件,如`&lt;a4j:commandButton&gt;`、`&lt;a4j:commandLink&gt;`等,这些组件可以触发Ajax请求并更新页面的部分区域。 - **Ajax 行为**:Ajax4JSF 提供了Ajax行为组件,如`...

Global site tag (gtag.js) - Google Analytics