As i know,there are 4 ways to pass a parameter value from JSF page to backing bean :

  1. Method expression (JSF 2.0)
  2. f:param
  3. f:attribute
  4. f:setPropertyActionListener

Let see example one by one :

1. Method expression

Since JSF 2.0, you are allow to pass parameter value in the method expression like this #{bean.method(param)}.

JSF page…

<h:commandButton action="#{user.editAction(delete)}" />

Backing bean…

@ManagedBean(name="user")
@SessionScoped
public class UserBean{ public String editAction(String id) {
//id = "delete"
} }

2. f:param

Pass parameter value via f:param tag and get it back via request parameter in backing bean.

JSF page…

<h:commandButton action="#{user.editAction}">
<f:param name="action" value="delete" />
</h:commandButton>

Backing bean…

@ManagedBean(name="user")
@SessionScoped
public class UserBean{ public String editAction() { Map<String,String> params =
FacesContext.getExternalContext().getRequestParameterMap();
String action = params.get("action");
//... } }

3. f:atribute

Pass parameter value via f:atribute tag and get it back via action listener in backing bean.

JSF page…

<h:commandButton action="#{user.editAction}" actionListener="#{user.attrListener}">
<f:attribute name="action" value="delete" />
</h:commandButton>

Backing bean…

@ManagedBean(name="user")
@SessionScoped
public class UserBean{ String action; //action listener event
public void attrListener(ActionEvent event){ action = (String)event.getComponent().getAttributes().get("action"); } public String editAction() {
//...
} }

4. f:setPropertyActionListener

Pass parameter value via f:setPropertyActionListener tag, it will set the value directly into your backing bean property.

JSF page…

<h:commandButton action="#{user.editAction}" >
<f:setPropertyActionListener target="#{user.action}" value="delete" />
</h:commandButton>

Backing bean…

@ManagedBean(name="user")
@SessionScoped
public class UserBean{ public String action; public void setAction(String action) {
this.action = action;
} public String editAction() {
//now action property contains "delete"
} }

4 ways to pass parameter from JSF page to backing bean的更多相关文章

  1. PHP Fatal error: Cannot pass parameter 2 by reference

    PHP Fatal error:  Cannot pass parameter 2 by reference in 这个错误的意思是:不能按引用传递第2个参数 我的理解是: 方法的第2个参数 需要传递 ...

  2. jquery pass parameter to ajax callback

    $('.del').on('click', function () { var id = $(this).attr('id'); var url = '/m/g2_content_del/' + id ...

  3. pass parameter by endpoint, this is for websocket

    使用了Java的字符串:@ServerEndpoint("/chat/{room}")public class MyEndpoint {@OnMessagepublic void ...

  4. 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 ...

  5. [转载][翻译] 利用JSF、SpringFramework和Hibernate构建Web应用的实例讲述

    [原作者] Derek Yang Shen[原文链接] http://www.javaworld.com/javaworld/jw-07-2004/jw-0719-jsf.html[源码链接] htt ...

  6. JSF和Struts的区别概述

    JSF和Struts的区别概述,都采用taglib来处理表示层:在jsp页面中,二者都是采用一套标记库来处理页面的表示和model层的交互. 据说JSF的主要负责人就是struts的主要作者,所以二者 ...

  7. JSF 2 dropdown box example

    In JSF, <h:selectOneMenu /> tag is used to render a dropdown box – HTML select element with &q ...

  8. JSF 2 multiple select listbox example

    In JSF, <h:selectManyListbox /> tag is used to render a multiple select listbox – HTML select ...

  9. JSF 2 listbox example

    In JSF, <h:selectOneListbox /> tag is used to render a single select listbox – HTML select ele ...

随机推荐

  1. 222. Count Complete Tree Nodes -- 求完全二叉树节点个数

    Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...

  2. iOS UI-自动布局(Autoresizing)

    // // ViewController.m // IOS_0115_buzhi // // Created by ma c on 16/1/15. // Copyright (c) 2016年 博文 ...

  3. 【hive】求日期是星期几

    在Hive原生版本中,目前并没有返回星期几的函数.除了利用java自己编写udf外,也可以利用现有hive函数实现. 方法格式: pmod(datediff('#date#', '任意年任意一个星期日 ...

  4. 201621123010《Java程序设计》第5周学习总结

    1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 接口.面向接口编程 interface.implements has-a 关系 Comparable.Comparator 1. ...

  5. python切片取值和下标取值时,超出范围怎么办?

    可迭代对象下标取值超出索引范围,会报错:IndexError 可迭代切片取值超出索引范围,不报错,而是返回对应的空值. a=[1,2,3,4] a[99] Traceback (most recent ...

  6. 2018-2019-2 《网络对抗技术》Exp1 PC平台逆向破解 20165222

    Exp1 PC平台逆向破解 1,掌握NOP, JNE, JE, JMP, CMP汇编指令的机器码 NOP:空指令,作用就是直接跳到下一指令.机器码为:90. JNE:判断0标志位,不等于0跳转.机器码 ...

  7. Nginx配置IPv6端口监听及务器设置IPV6及Https支持并通过AppStore审核

    一.监听端口 从Nginx 1.3的某个版本起,默认ipv6only是打开的,所以,我们只需要在监听中加入ipv6监听即可,不过推荐都手动加上比较好,代码如下: listen [::]: ipv6on ...

  8. Linux之 linux7防火墙基本使用及详解

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld  停止: systemctl disab ...

  9. 对类 sizeof

    sizeof一个类的时候,都什么会被计算?静态成员会被计算进来么?如果这是一个子类,它的父类成员会被计算么? #include <iostream> using namespace std ...

  10. Mac 下使用brew install 报错: Cowardly refusing to `sudo brew install'

    Mac 下使用brew install 报错: localhost:infer-osx-v0.6.0 admin$ sudo brew install opam Error: Cowardly ref ...