JSF 1.1 中的面板弹出窗口
JSF 1.1 中是否可以有面板弹出窗口?我想在单击编辑按钮时显示一个弹出窗口,然后希望在该面板弹出窗口中包含几个组件。
我没有使用任何其他 JSF,如icefaces 或 richfaces,只是普通的 JSF 1.1。
任何帮助都是非常值得赞赏的。
谢谢
Is it possible to have panel popup window in JSF 1.1 ? I would like to display a popup window when I click edit button and then would like to have few components in that panel popup window.
I am not using any other JSF like icefaces or richfaces, just plain JSF 1.1.
Any help is highly appreciable.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这绝对有可能。只需引入一些 JavaScript 和/或 CSS 的好镜头即可显示/隐藏弹出窗口并设置其样式。这也是像 RichFaces 这样的普通组件库正在做的事情,唯一的区别是它全部包装在一个简单的 JSF 组件中。
最简单的是,您可以在单击按钮/链接时使用 JS
window.open()
。window.open()
允许对窗口进行细粒度的自定义,例如大小和要显示/隐藏的浏览器栏。阅读 MDN 文档以了解它们。必须返回false
以防止按钮不必要地提交表单。然后,在与
edit.jsf
关联的支持 bean 的构造函数中,您可以通过作为请求参数传递的id
来获取项目。令人讨厌的是,但这就是 JSF 1.1 所得到的结果,它不提供 JSF 1.2 支持的
@PostConstruct
注释或 JSF 2.0 支持的
标记。最后,在
edit.jsf
中,您需要引入一些条件渲染的 JavaScript 片段,该片段会重新加载父窗口(以便重新显示编辑的数据)并关闭弹出窗口。当保存成功时,在操作方法中设置
success
布尔值。还存在使用所谓的“覆盖窗口”对话框的解决方案,该对话框基本上是
,它使用 CSS
position:fixed;
定位并跨越整个浏览器窗口具有透明背景,然后其中有另一个居中并包含真实形式的。然而,这需要更多的 JS/CSS。这也是一般的 JSF 组件库和 JavaScript 框架/插件(例如 jQuery 或 YUI)基本上所做的事情。让它与 JSF 无缝协作只是比较棘手,因为您当然希望在弹出表单上发生验证错误等情况时重新显示弹出窗口。如果您使用支持 ajax 的 JSF 实现/库,那就容易多了。
Yes, it's definitely possible. Just bring in some good shot of JavaScript and/or CSS to show/hide and style the popup window. That's also what the average component library like RichFaces is doing with the only difference that it's all wrapped in a simple JSF component.
At its simplest you can use JS
window.open()
on click of a button/link.The
window.open()
allows for fine grained customization of the window, such as the size and the browser bars which are to be displayed/hidden. Read the MDN documentation to learn about them. Returningfalse
is mandatory to prevent the button from unnecessarily submitting the form.Then, in the constructor of the backing bean associated with
edit.jsf
, you can grab the item by theid
which is been passed as request parameter.Nasty, but that's what you get with JSF 1.1 which doesn't offer a JSF 1.2-supported
@PostConstruct
annotation or JSF 2.0-supported<f:viewParam>
tag.Finally, in the
edit.jsf
you need to bring in some conditionally rendered JavaScript piece which reloads the parent window (so that the edited data is redisplayed) and closes the popup window.Set the
success
boolean in the action method when the saving is successful.There exist also solutions using a so-called "overlay window" dialog which is basically
<div>
which is positioned using CSSposition: fixed;
and spans the entire browser window with a transparent background and then therein another<div>
which is centered and contains the real form. This however requires a bigger shot of JS/CSS. This is also what the average JSF component library and JavaScript framework/plugin (such as jQuery or YUI) is basically doing. It's only trickier to get it work seamlessly together with JSF as you would of course like to redisplay the popup when a validation error on the popup form occurs and that kind of things. It's much easier if you're using an ajax-enabled JSF implementation/library.