30.2. <w:button>

Button构件与HTML的button是对应的,提供了常用的按钮功能,并加了一些额外的特性。

30.2.1. 构件信息

表 30.2. 构件信息

Component Typeorg.operamasks.faces.component.widget.UIButton
Component Familyjavax.faces.Command
Component Classorg.operamasks.faces.component.widget.UIButton
Tag Classorg.operamasks.faces.webapp.widget.UIButtonTag
Renderer Typeorg.operamasks.faces.component.widget.UIButton
Renderer Class(AJAX)org.operamasks.faces.render.widget.ajax.AjaxButtonRenderer

继承体系

+java.lang.Object

++javax.faces.component.UIComponent

+++javax.faces.component.UIComponentBase

++++javax.faces.component.UICommand

+++++javax.faces.component.html.HtmlCommandButton

++++++org.operamasks.faces.component.widget.base.UIButtonBase

+++++++org.operamasks.faces.component.widget.UIButton

30.2.2. 属性

表 30.3. 属性

accesskey 定义类 javax.faces.component.html.HtmlCommandButton
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
对象的键盘快捷键
action 定义类 javax.faces.component.UICommand
类型 javax.el.MethodExpression(javax.el.MethodExpression)
是否必须 延时求值
特定Action事件激活时调用的方法
actionBinding 定义类 org.operamasks.faces.component.widget.base.UIButtonBase
类型 javax.el.ValueExpression(org.operamasks.faces.component.action.Action)
是否必须 延时求值
可以绑定一个org.operamasks.faces.component.action.Action的对象到该属性上,当按钮被点击时,Action对象的processAction方法将被执行.
actionListener 定义类 javax.faces.component.UICommand
类型 javax.el.MethodExpression(javax.el.MethodExpression)
是否必须 延时求值
特定ActionEvent事件激活时调用的方法
allowReEnter 定义类 org.operamasks.faces.component.widget.UIButton
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
在提交请求后是否允许用户在请求响应完成之前重复提交. 如果设置为false,在用户提交请求时,按钮将变为不可用,在请求响应完成时按钮将变为可用.
alt 定义类 javax.faces.component.html.HtmlCommandButton
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
用于替代图像的文本
alwaysSubmit 定义类 org.operamasks.faces.component.widget.UIButton
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
当按钮的type未设置为submit时,是否在每次点击按钮时提交表单.
binding 定义类 javax.faces.component.UIComponentBase
类型 javax.el.ValueExpression(javax.faces.component.UIComponent)
是否必须 延时求值
一个值表达式,用于把该组件链接到一个ManagedBean的某个属性。
dir 定义类 javax.faces.component.html.HtmlCommandButton
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
对象的阅读顺序
disabled 定义类 javax.faces.component.html.HtmlCommandButton
类型 javax.el.ValueExpression(boolean)
是否必须 延时求值
用户是否可与该对象交互
id 定义类 javax.faces.component.UIComponentBase
类型 java.lang.String
是否必须 延时求值
这个组件的组件标识符。这个值在最近的命名容器类型的父组件范围内,必须是唯一的。
ignoreSubmits 定义类 org.operamasks.faces.component.widget.UIButton
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
是否跳过validate和updateModel
image 定义类 javax.faces.component.html.HtmlCommandButton
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
对象装入图片的URL
immediate 定义类 javax.faces.component.UICommand
类型 javax.el.ValueExpression(boolean)
是否必须 延时求值
是否跳过验证
initConfig 定义类 org.operamasks.faces.component.widget.UIButton
类型 javax.el.ValueExpression(java.lang.Object)
是否必须 延时求值
初始化对象,取值可以是ExtConfig对象, 或String,表示一个JavaScript对象,比如:{"a": "avalue", "b":true, "c":200, "d":"var::dvalue"} 如果取值是表示一个JavaScript对象的String,则key必须用(双)引号包起来,比如"a"。
isAjaxSubmit 定义类 org.operamasks.faces.component.widget.UIButton
类型 javax.el.ValueExpression(java.lang.Boolean)
是否必须 延时求值
设置按钮提交的形式是否是ajax,默认为true,如果为false,则以非ajax形式提交,导致页面重刷.
jsvar 定义类 org.operamasks.faces.component.widget.UIButton
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
客户端脚本使用的javascript变量名,使用此变量名可以在客户端脚本中引用构件对应的客户端对象.
label 定义类 javax.faces.component.html.HtmlCommandButton
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
对象的标签
lang 定义类 javax.faces.component.html.HtmlCommandButton
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
设置或获取要使用的语言
minWidth 定义类 org.operamasks.faces.component.widget.UIButton
类型 javax.el.ValueExpression(java.lang.Integer)
是否必须 延时求值
按钮的最小宽度.
onblur 定义类 javax.faces.component.html.HtmlCommandButton
类型 java.lang.String
是否必须 延时求值
在对象失去输入焦点时触发
onchange 定义类 javax.faces.component.html.HtmlCommandButton
类型 java.lang.String
是否必须 延时求值
在对象值发生改变时触发
onclick 定义类 javax.faces.component.html.HtmlCommandButton
类型 java.lang.String
是否必须 延时求值
在用户用鼠标左键单击对象时触发
ondblclick 定义类 javax.faces.component.html.HtmlCommandButton
类型 java.lang.String
是否必须 延时求值
当用户双击对象时触发
onfocus 定义类 javax.faces.component.html.HtmlCommandButton
类型 java.lang.String
是否必须 延时求值
当对象获得焦点时触发
onkeydown 定义类 javax.faces.component.html.HtmlCommandButton
类型 java.lang.String
是否必须 延时求值
当用户按下键盘按键时触发
onkeypress 定义类 javax.faces.component.html.HtmlCommandButton
类型 java.lang.String
是否必须 延时求值
当用户按下键盘键时触发
onkeyup 定义类 javax.faces.component.html.HtmlCommandButton
类型 java.lang.String
是否必须 延时求值
当用户释放键盘按键时触发
onmousedown 定义类 javax.faces.component.html.HtmlCommandButton
类型 java.lang.String
是否必须 延时求值
当用户用任何鼠标按钮单击对象时触发
onmousemove 定义类 javax.faces.component.html.HtmlCommandButton
类型 java.lang.String
是否必须 延时求值
当用户将鼠标划过对象时触发
onmouseout 定义类 javax.faces.component.html.HtmlCommandButton
类型 java.lang.String
是否必须 延时求值
当用户将鼠标指针移出对象边界时触发
onmouseover 定义类 javax.faces.component.html.HtmlCommandButton
类型 java.lang.String
是否必须 延时求值
当用户将鼠标指针移动到对象内时触发
onmouseup 定义类 javax.faces.component.html.HtmlCommandButton
类型 java.lang.String
是否必须 延时求值
当用户在鼠标位于对象之上时释放鼠标按钮时触发
onselect 定义类 javax.faces.component.html.HtmlCommandButton
类型 java.lang.String
是否必须 延时求值
对象被选中时触发
readonly 定义类 javax.faces.component.html.HtmlCommandButton
类型 javax.el.ValueExpression(boolean)
是否必须 延时求值
对象是否只读
rendered 定义类 javax.faces.component.UIComponentBase
类型 boolean(boolean)
是否必须 延时求值
一个标志,指出该组件是否要在任何随后的form提交过程中被渲染或处理。 这个属性的缺省值是true。
style 定义类 javax.faces.component.html.HtmlCommandButton
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
为该设置元素设置内嵌样式
styleClass 定义类 javax.faces.component.html.HtmlCommandButton
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
设置或获取对象的样式类
tabindex 定义类 javax.faces.component.html.HtmlCommandButton
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
设置或获取定义对象的Tab顺序的索引
title 定义类 javax.faces.component.html.HtmlCommandButton
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
设置或获取对象的工具提示
tooltip 定义类 org.operamasks.faces.component.widget.UIButton
类型 javax.el.ValueExpression(java.lang.String)
是否必须 延时求值
鼠标经过时的弹出信息.
value 定义类 javax.faces.component.UICommand
类型 java.lang.String
是否必须 延时求值
构件的当前值
width 定义类 org.operamasks.faces.component.widget.UIButton
类型 javax.el.ValueExpression(java.lang.Integer)
是否必须 延时求值
按钮的宽度.

30.2.3. 构件API

30.2.3.1. UIButton(Button构件类)

表 30.4. 常用方法

bindAction 方法签名 public void bindAction(String el)
参数说明 el: 指定Action方法的EL表达式
返回值 无返回值
方法描述 动态绑定构件对应的Action方法。
bindActionListener 方法签名 public void bindActionListener(String el)
参数说明 el: 指定ActionListener方法的EL表达式
返回值 无返回值
方法描述 动态绑定构件对应的ActionListener方法。

30.2.4. 示例

以下的例子介绍了w:button标签最常用的用法,"value"属性是w:button显示的文本,当点击w:button的时候,就会执行"action"属性绑定的后台方法。注意,w:button要放在w:form里面,不然不会提交到服务器。

<f:view>
<w:page>
    <w:form>
        <w:button value="Button" action="#{SampleBean.button_action}"/>
    </w:form>
</w:page>
</f:view>

上面的代码是普通的提交方法,如果要用ajax的方法来提交,很简单,只需要给<f:view>加上个renderKitId="AJAX"就行了,如下

<f:view renderKitId="AJAX"> 
<w:page>
  <w:form> 
    <w:button value="Button" action="#{SampleBean.button_action}"/> 
  </w:form> 
</w:page>
</f:view>