如何在 JSF2/JPA/无状态 EBJ(jsf 托管控制器)中从一个视图导航到下一个视图并保留数据
我有一个使用 JSF2 和 JPA 实体的 Web 应用程序,无状态 ejb 会话 bean 作为我的外观/ejb 对象,托管 bean(请求和视图范围)作为公开业务方法的控制器,托管控制器从注入的无状态会话 bean 中提取数据。
但我很困惑如何在此环境中的控制器中跨视图导航和保留数据,例如:
我有一个 jsf2 视图页面 (departmentView.xhtml),它显示 Department 对象列表,并且每行都有一个编辑项。单击编辑我想加载新页面并显示 在新页面上该部门的列表或员工,所以我调用员工控制器,将所选部门传递给它,
action="#{employeeController.getEmployeeListForADepartment(ithDepartment)}"
这里是我的departmentView.xhtml的片段
<h:dataTable id="table" value="#{departmentController.departmentList}"
var="ithDepartment">
...
<h:column>
<h:commandLink id="editId" value="Edit"
action="#{employeeController.getEmployeeListForADepartment(ithDepartment)}" />
</h:column>
,我的employeeController被定义为
ManagedBean(name = "employeeController")
@ViewScoped
public class EmployeeController implements Serializable {
...
private List<Employee> employeeList = new ArrayList<Employee>();
...
@EJB
private com.ejb.session.EmployeeFacade ejbEmployeeFacade;
...
public List<Employee> getEmployeeListForADepartment(Department dept)
{
if(employeeList==null || employeeList.isEmpty())
employeeList = ejbEmployeeFacade.findEmployeesByDepartment(dept);
// now i want to navigate to the employee view showing these employees for the
// selected department.
// but this navigation below triggers creating a new EmployeeController
// and i lose my employeeList
return "employeeView";
}
我真的想避免使用jsf会话范围,并且相信有一种方法可以做到这一点,只是不要在我的任何 jsf/ejb 书中阅读它。
大声思考,也许没有 EmployeeController.getEmployeeListForADepartment(..)
进行查找,只需从部门 ID 创建一个参数并通过 return "employeeView?departmentId=X" 传递该参数;
并让构造函数查找 id 是否存在?
可以帮我找到在 EJB/JSF2 环境中实现此功能的正确方法吗?
谢谢
I have a web app using JSF2 with JPA Entities, Stateless ejb session beans as my facade/ejb objects, and managed beans (request and view scoped) as controllers exposing business methods, managed controllers are pulling data from the injected stateless session beans.
but i am confused how to navigate and retain data accross views in my controllers in this environment, for example:
I have a jsf2 view page (departmentView.xhtml) that displays a list of Department objects and each row has an edit item. Clicking edit I want to load a new page and display
a list or Employee's for that department on the new page, so i invoke the Employee controller passing it the selected Department
action="#{employeeController.getEmployeeListForADepartment(ithDepartment)}"
here is a snippet of my departmentView.xhtml
<h:dataTable id="table" value="#{departmentController.departmentList}"
var="ithDepartment">
...
<h:column>
<h:commandLink id="editId" value="Edit"
action="#{employeeController.getEmployeeListForADepartment(ithDepartment)}" />
</h:column>
and my employeeController is defined as
ManagedBean(name = "employeeController")
@ViewScoped
public class EmployeeController implements Serializable {
...
private List<Employee> employeeList = new ArrayList<Employee>();
...
@EJB
private com.ejb.session.EmployeeFacade ejbEmployeeFacade;
...
public List<Employee> getEmployeeListForADepartment(Department dept)
{
if(employeeList==null || employeeList.isEmpty())
employeeList = ejbEmployeeFacade.findEmployeesByDepartment(dept);
// now i want to navigate to the employee view showing these employees for the
// selected department.
// but this navigation below triggers creating a new EmployeeController
// and i lose my employeeList
return "employeeView";
}
i really want to avoid using jsf session scope, and believe there is a way to do this, just not reading about it in any of my jsf/ejb books.
thinking outloud, maybe don't have EmployeeController.getEmployeeListForADepartment(..)
do a lookup, just create a parameter from the department id and pass that along via return "employeeView?departmentId=X";
and have constructor then do a lookup if the id is present?
can somehelp me with the proper way to implement this in EJB/JSF2 environment
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在源视图中使用简单的 GET
来传递部门 ID,并在目标视图中使用
来转换和设置部门。例如
,
另请
参阅:
Use a simple GET
<h:link>
in the source view to pass the department ID and a<f:viewParam>
in the target view to convert and set the department.E.g.
with
and
See also: