JSF 2 button and commandButton example
In JSF 2.0, both <h:button />
and <h:commandButton />
tags are used to render HTML input element of type button, with different mechanism to handle the navigation.
1. JSF h:commandButton
example
The “h:commandButton
” tag is released since JSF 1.x, you can declare the bean, which return the navigation outcome in the “action
” attribute. If browser’s with JavaScript disabled, the navigation is still working, because the navigation is handled via form post.
1. Submit button
//JSF
<h:commandButton value="submit" type="submit" action="#{user.goLoginPage}" />
//HTML output
<input type="submit" name="xxx" value="submit" />
2. Reset button
//JSF
<h:commandButton value="reset" type="reset" />
//HTML output
<input type="reset" name="xxx" value="reset" />
3. Normal button
//JSF
<h:commandButton value="button" type="button" />
//HTML output
<input type="button" name="xxx" value="button" />
4. Normal button with onclick event
//JSF
<h:commandButton value="Click Me" type="button" onclick="alert('h:commandButton');" />
//HTML output
<input type="button" name="xxx" value="Click Me" onclick="alert('h:commandButton');" />
2. JSF h:button example
The “h:button
” is a new tag in JSF 2.0, you can declared the navigation outcome directly in the “outcome
” attribute, no need to call a bean to return an outcome like “h:commandButton
” above. But, if browser’s with JavaScript disabled, the navigation will failed, because the “h:button
” tag is generate an “onclick
” event to handle the navigation via “window.location.href
”. See examples :
1. Normal button without outcome
//JSF
<h:button value="buton" />
//HTML output
<input type="button"
onclick="window.location.href='/JavaServerFaces/faces/currentpage.xhtml; return false;"
value="buton" />
P.S if the outcome attribute is omitted, the current page URL will treat as the outcome.
2. Normal button with an outcome
//JSF
<h:button value="buton" outcome="login" />
//HTML output
<input type="button"
onclick="window.location.href='/JavaServerFaces/faces/login.xhtml; return false;"
value="buton" />
3. Normal button with JavaScript.
//JSF
<h:button value="Click Me" onclick="alert('h:button');" />
//HTML output
<input type="button"
onclick="alert('h:button');window.location.href='/JavaServerFaces/faces/page.xhtml;return false;"
value="Click Me" />
My thought…
No really sure why JSF 2.0 released this “h:button
” tag, the JavaScript redirection is not practical, especially in JavaScript disabled browser. The best is integrate the “outcome” attribute into the “h:commandButton
” tag, hope it can be done in future release.
JSF 2 button and commandButton example的更多相关文章
- JSF 与 HTML 标签的联系
*页面的开头 <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@ t ...
- Ajax4Jsf 简单介绍
Ajax4jsf 允许开发人员将 Ajax 功能添加到 JSF 应用程序中,而不需要 JavaScript 或用 Ajax 图形部件替换现有的组件.这个包还允许在使用 Java 2D 库时动态地生成图 ...
- VSTO在幻灯片里面添加按钮对象
//添加Form窗体,窗体中添加Image控件,单击弹出"PPT"信息提示 //命名引用:using MF = Microsoft.Vbe.Interop.Forms; priva ...
- 关于JSF中immediate属性的总结(二)
The immediate attribute in JSF is commonly misunderstood. If you don't believe me, check out Stack O ...
- Parameter Passing / Request Parameters in JSF 2.0 (转)
This Blog is a compilation of various methods of passing Request Parameters in JSF (2.0 +) (1) f:vi ...
- JSF页面中使用js函数回调后台bean方法并获取返回值的方法
由于primefaces在国内使用的并不是太多,因此,国内对jsf做系统.详细的介绍的资料很少,即使有一些资料,也仅仅是对国外资料的简单翻译或者是仅仅讲表面现象(皮毛而已),它们的语句甚至还是错误的, ...
- JSF 2 dropdown box example
In JSF, <h:selectOneMenu /> tag is used to render a dropdown box – HTML select element with &q ...
- JSF 2 multiple select listbox example
In JSF, <h:selectManyListbox /> tag is used to render a multiple select listbox – HTML select ...
- JSF 2 listbox example
In JSF, <h:selectOneListbox /> tag is used to render a single select listbox – HTML select ele ...
随机推荐
- SQL计算实际工作日(天)及两个时间(工作日)间隔(小时)!
Code highlighting produced by Actipro CodeHighlighter (freeware)-->去掉法定节假日(周六,周天)和指定节假日 USE [DBNa ...
- jQuery_效果(滑动)
1.jQuery slideDown() 方法(用于向下滑动元素) 语法:$(selector).slideDown(speed,callback); 可选的 speed 参数规定效果的时长.它可以取 ...
- R语言实现数据集某一列的频数统计——with和table
with(priority.train, table(From.EMail)) 统计priority.train中From.EMail的频数
- [Swift 语法点滴]——数组参数
Swift语言一如既往的继承了苹果公司卓尔不群的奇葩思维方式,总是要弄得跟别的语言不一样,才能显出它的特殊 比如用数组作为参数上,这格式实在是没有试出来,找了stackoverflow,才找到相应信息 ...
- 最大熵模型 Maximum Entropy Model
熵的概念在统计学习与机器学习中真是很重要,熵的介绍在这里:信息熵 Information Theory .今天的主题是最大熵模型(Maximum Entropy Model,以下简称MaxEnt),M ...
- PHP实现站点pv,uv统计(一)
具体步骤分为数据采集脚本,数据收取服务,数据分析脚本,数据存储服务 采集脚本一般有两种形式,一种是简单的页面插入一个图片进行请求,一种是复杂的动态生成js标签,引入一段js(这时采集服务器会网往客户端 ...
- 三:分布式事务一致性协议2pc和3pc
一:分布式一致性协议--->对于一个分布式系统进行架构设计的过程中,往往会在系统的可用性和数据一致性之间进行反复的权衡,于是就产生了一系列的一致性协议.--->长期探索涌现出一大批经典的一 ...
- 定时组件quartz系列<二>quartz的原理
Quartz是一个大名鼎鼎的Java版开源定时调度器,功能强悍,使用方便. 一.核心概念 Quartz的原理不是很复杂,只要搞明白几个概念,然后知道如何去启动和关闭一个调度程序即可. 1. ...
- webstorm安装破解版
破解方法: 现在有个比较简单的注册方法.注册时选择“License server”输入“http://15.idea.lanyus.com/”点击“OK”即可快速激活JetBrains系列产品”
- 二级缓存处理大数据 用ehcache.xml配置文件
二级缓存大量数据的解决方案 数据很大 二级缓存 存储大数据,让 内存和磁盘文件进行交互,数据库中的不变的数据在磁盘上,这样就可以少和数据库进行交互了 ehcache.xml 放在src下 <eh ...