32.12. <ajax:submitAction>

使用<ajax:submitAction>构件可以方便地发送ajax请求,而避免隐藏button发送请求的情况。

32.12.1. 构件信息

表 32.27. 构件信息

Component Typeorg.operamasks.faces.component.ajax.AjaxSubmitAction
Component Familyorg.operamasks.faces.AjaxSubmitAction
Component Classorg.operamasks.faces.component.ajax.AjaxSubmitAction
Tag Classorg.operamasks.faces.webapp.ajax.AjaxSubmitActionTag
Renderer Typeorg.operamasks.faces.component.ajax.AjaxSubmitAction
Renderer Class(AJAX)org.operamasks.faces.render.ajax.AjaxSubmitActionRenderer

继承体系

+java.lang.Object

++javax.faces.component.UIComponent

+++javax.faces.component.UIComponentBase

++++javax.faces.component.UICommand

+++++org.operamasks.faces.component.ajax.base.AjaxSubmitActionBase

++++++org.operamasks.faces.component.ajax.AjaxSubmitAction

32.12.2. 属性

表 32.28. 属性

action 定义类 javax.faces.component.UICommand
类型 javax.el.MethodExpression(javax.el.MethodExpression)
是否必须 延时求值
特定Action事件激活时调用的方法
actionListener 定义类 javax.faces.component.UICommand
类型 javax.el.MethodExpression(javax.el.MethodExpression)
是否必须 延时求值
特定ActionEvent事件激活时调用的方法
binding 定义类 javax.faces.component.UIComponentBase
类型 javax.el.ValueExpression(javax.faces.component.UIComponent)
是否必须 延时求值
一个值表达式,用于把该组件链接到一个ManagedBean的某个属性。
groupId 定义类 org.operamasks.faces.component.ajax.AjaxSubmitAction
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
与该组件同时提交的form组标识名
id 定义类 javax.faces.component.UIComponentBase
类型 java.lang.String
是否必须 延时求值
这个组件的组件标识符。这个值在最近的命名容器类型的父组件范围内,必须是唯一的。
immediate 定义类 javax.faces.component.UICommand
类型 javax.el.ValueExpression(boolean)
是否必须 延时求值
是否跳过验证
isAjaxSubmit 定义类 org.operamasks.faces.component.ajax.AjaxSubmitAction
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
Action的提交形式
jsvar 定义类 org.operamasks.faces.component.ajax.AjaxSubmitAction
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
组件客户端js变量名
rendered 定义类 javax.faces.component.UIComponentBase
类型 boolean(boolean)
是否必须 延时求值
一个标志,指出该组件是否要在任何随后的form提交过程中被渲染或处理。 这个属性的缺省值是true。
value 定义类 javax.faces.component.UICommand
类型 java.lang.String
是否必须 延时求值
构件的当前值

32.12.3. 构件API

32.12.4. 例子

下面的例子介绍了<ajax:submitAction>的使用: 点击链接时发送一个ajax请求,并在发送前添加了"key"、"anotherKey1"、"anotherKey2"的参数,且一并提交了id为"anotherForm"的form中的所有input。

<ajax:submitAction immediate="false" action="#{testBean.submit}" jsvar="submitAction1" submitForms="anotherForm">
    <ajax:param name="key" value="keyValue1"> 
</ajax:submitAction> 
<a onclick="submitAction.addParam('anotherKey1','anotherKeyValue1');submitAction.addPermParam('anotherKey2','anotherKeyValue2');submitAction.submit();"></a>

其中addParam(key,value)是添加临时参数(只对本次submit()有效),addPermParam(key,value)是添加永久参数(对本次及以后的所有submit()都有效)。ajax:submitAction的子组件ajax:param作用等同于addPermParam(key,value)。ajax:submitAction提交的参数可以在后台通过以下方式取出:

public void  submit(){
    Map<String,String> reqParams=FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
    String key=reqParams.get('key');
    String anotherKey1=reqParams.get('anotherKey1');
    String anotherKey2=reqParams.get('anotherKey2');
}