在页面之间发送参数的最佳方法是什么? [英] Whats the best way of sending parameters between pages?

查看:100
本文介绍了在页面之间发送参数的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在项目中使用的是JSF(当时还很陌生),因为每个页面都有一个back bean Java文件.

We are using JSF in our project (im pretty new to it) were every page have a back bean Java file.

为了从一个页面移动(重定向)到另一页面,我需要在重定向之前将所有参数(搜索条件)放在请求范围内,然后在下一页构造函数中将其取回.当您只有几页深的书并且想回到顶部时,维护变得很烦人.

In order to move (redirect) from one page to another, i need to put all the parameters (search criteria) in the request scope before redirecting and then retrieve it back in the next page constructor. When you have few pages deep and you want to come back to the top, it becomes really annoying to maintain.

例如,如果我有一个带有高级搜索过滤器的页面1,该页面会根据所选项目重定向到页面2,而从页面2会得到另一个列表,您可以转到页面3以获得详细信息.现在,每次我需要将所有参数放入请求范围/再次阅读它们,将它们存储在隐藏字段中并取回它们.

For example, if i have page 1 with advanced search filters, which redirects to page 2, depending on the chosen item, and from page 2, you get another list were you can go to page 3 for details. Now each time i need to put all the params in the request scope/read them again, store them in hidden fields and get them back.

此方法到底有什么问题,以及在JSF中有什么更好的方法?

Whats exactly wrong with this method and whats a better way to do it in JSF?

EDIT :环境是IBM Rational Application Developer(RAD),它具有自己的JSF实现.不确定是否会有所不同.

EDIT: the environment is IBM Rational Application Developer (RAD), which have its own JSF implementation. Not sure if that makes a difference.

推荐答案

如果要在多个窗口/选项卡中打开同一页面,则在会话范围内放置请求范围的数据将(非常)困难.仅在数据本身也是真正会话范围的情况下才使用会话范围(出色的示例是登录用户"和购物车",您希望它们在整个过程中都完全相同)会议).同样,不要将请求范围的数据放在会话范围内.这会伤害到您和最终用户.

Putting request scoped data in session scope will bite you (very) hard if you're going to open the same page in multiple windows/tabs. Only use the session scope if the data itself is also really session scoped (excellent examples are the "logged-in user" and the "shopping cart", you want it to be exactly the same throughout the entire session). Again, don't put request scoped data in the session scope. It hurts both you and the enduser.

仅将您的bean设计得很聪明(使不同的bean包含相同的数据是没有意义的),并在需要的地方使用h:inputHidden,如果有必要,将其与托管属性注入结合使用.确实,编码和维护有点麻烦.另一方面,如果要传递的数据实际上是 Tomahawk <t:saveState>和整个"托管Bean一样大.它在JSF页面中仅需一行,并且一直提供很大的帮助.

Just design your beans smart (it makes no sense to have different beans containing the same data) and make use of h:inputHidden where needed, if necessary in combination with managed property injection. It's indeed a bit a pain to code and maintain. You can on the other hand also just grab Tomahawk <t:saveState> if the to-be-passed data is actually as big as a "whole" managed bean. It costs only a single line in the JSF page and has always been of great assistance.

*例如,如果我有一个带有高级搜索过滤器的页面1,该页面会根据所选项目重定向到页面2,从页面2会得到另一个列表,您可以转到页面3以获得详细信息.现在,每次我需要将所有参数放入请求范围/再次阅读它们,将它们存储在隐藏字段中并取回它们.

*For example, if i have page 1 with advanced search filters, which redirects to page 2, depending on the chosen item, and from page 2, you get another list were you can go to page 3 for details. Now each time i need to put all the params in the request scope/read them again, store them in hidden fields and get them back.

此方法到底有什么问题,以及在JSF中有什么更好的方法?*

Whats exactly wrong with this method and whats a better way to do it in JSF?*

此方法没有任何问题.也许您以错误的方式编写了代码,从而导致它看起来不必要地过于复杂.只要您不发布有关所使用代码的详细信息,我就不会说太多.

There's nothing wrong with this method. Maybe you coded it the wrong way which caused that it looks unnecessarily overcomplicated. I can't tell much as long as you don't post details about the code used.

根据您的修改:

环境是IBM Rational Application Developer(RAD),它具有自己的JSF实现.不确定是否会有所不同.

这不是事实. IBM没有任何JSF实施.它只有一个组件库(维护不佳的hx前缀组件,也称为"Faces Client Framework"). WSAD/RAD附带有Sun JSF RI(Mojarra)作为标准JSF实现,尽管它通常是一个过时的版本.确保您保持更新.

This is not true. IBM doesn't have any JSF implementation. It has just a component library (the poorly maintained hx prefixed components, also known as "Faces Client Framework"). WSAD/RAD ships with Sun JSF RI (Mojarra) as standard JSF implementation, although it's usually a heavily outdated version. Ensure that you keep it updated.

这篇关于在页面之间发送参数的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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