使用JSF 2.0在页面加载时使用参数初始化后备Bean [英] Initializng a Backing Bean With Parameters on Page Load with JSF 2.0

查看:125
本文介绍了使用JSF 2.0在页面加载时使用参数初始化后备Bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在页面加载时初始化备用bean.已经在寻找许多解决方案,但是大多数解决方案正在使用链接,按钮或根本没有参数.

I am trying to initialize a backing bean on page load. Already looked for many solutions, but most of them are using links,buttons or not having parameters at all.

场景: 客户登录到站点,然后应该在下一页上看到他的所有数据.

scenario: A customer logins to a site and then should see all of his data on the following page.

后备豆:

  1. loginDetailsController -支持 登录过程.可以访问用户的 密码和用户名.支持豆 用于Login.xhtml.

  1. loginDetailsController - to support login process. Can access user's password and username. Backing bean for Login.xhtml.

customerController -访问 其余的用户详细信息.它还具有一个customer_id字段.它是支持豆 用于Home.xhtml.可以完全从customer_id初始化customerController.

customerController - to access the rest of user details. It also has a customer_id field. It is the Backing bean for Home.xhtml. It is possible to initialize customerController entirely from customer_id.

在Home.xhtml上,可以通过以下方式获取customer_id:

On Home.xhtml it is possible to get customer_id this way:

 #{loginDetailsController.customer_id}

有没有一种方法可以在页面加载时使用上述值初始化customerController?

Is there a way to initialize customerController with the above value on page load?

此致

丹尼尔

推荐答案

这是我解决的方法:

因为LoginDetailsController是会话作用域的-客户ID总是被初始化.

Because LoginDetailsController is session scoped - customer_id is always initialized.

所以-我添加了

@ManagedProperty(value="#{loginDetailsController.customer_id}") 
private String customer_id;

加上-customer_id的获取器和设置器.

Plus - getter and setter for customer_id.

如Nikhil所说,在LoginDetailsController上-进行了一些更改. 然后,可以在Home.xhtml上使用#{customerController.customer_id}和其余的customerController初始化的customerController元素.

On LoginDetailsController, as Nikhil said - with a little change. Then, it is possible to use #{customerController.customer_id} and the rest of customerController initialized elements of customerController on Home.xhtml.

谢谢大家!

这篇关于使用JSF 2.0在页面加载时使用参数初始化后备Bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆