博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
4 ways to pass parameter from JSF page to backi...
阅读量:6282 次
发布时间:2019-06-22

本文共 2193 字,大约阅读时间需要 7 分钟。

  hot3.png

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…

Backing bean…

@ManagedBean(name="user") @SessionScopedpublic class UserBean{
  public String editAction(String id) {
//id = "delete" }  }
Note
If you are deploy JSF application in servlet container like Tomcat, make sure you include the “
el-impl-2.2.jar” properly. For detail, please read this article – .

2. f:param

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

JSF page…

Backing bean…

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

See a full here.

3. f:atribute

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

JSF page…

Backing bean…

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

See a full here.

4. f:setPropertyActionListener

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

JSF page…

Backing bean…

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

See a full here.

P.S Please share your idea, if you have any other ways :)

转载于:https://my.oschina.net/yida/blog/69615

你可能感兴趣的文章
linux下安装lnmp
查看>>
vue-cli 教程
查看>>
说说用过的几个远程工具
查看>>
开源项目Bug悬赏任务
查看>>
# python如何学习(二)
查看>>
怎么把图片转换成word?
查看>>
c# webbrowser 实现淘宝天猫链接转为淘宝客链接 有源码
查看>>
CentOS Rsync服务端与Windows cwRsync客户端实现数据同步
查看>>
ASM:ORA-15063 错误处理方法一则
查看>>
什么是Oracle高水位线?"high water mark"或HWM详解
查看>>
详解网络传输中的三张表,MAC地址表、ARP缓存表以及路由表
查看>>
android activity ImageView全屏设置
查看>>
linux java 定时任务
查看>>
Linux守护进程(init.d和xinetd)
查看>>
不能连接MS Sql Server2008数据库的问题
查看>>
nagios监控内存
查看>>
用python操作mysql数据库(之数据查询结果返回字典类型)
查看>>
DAY05 WINDOWS 打印机的设置以及磁盘管理
查看>>
那些打动人心的用户体验细节分享
查看>>
备考中
查看>>