菜单错误的解决方法
使用 Primefaces 2.2.1,如果菜单栏的子菜单对于浏览器窗口来说太大,它会出现在菜单栏上方(页面外部)并且无法使用。
简单的测试用例:
代码:
<p:menubar>
<p:submenu label="test">
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
...
</p:submenu>
<p:menubar>
如果将窗口尺寸减小到某个小的高度,您就可以看到问题。
它也发生在展示中,尽管子菜单被简单地隐藏了。
这使得它对于某些客户端(ipad)无法使用。
有什么解决方法或解决方案吗?
更新:我可以在此页面上重现该问题: http://wijmo.com/widgets/wijmo -打开/菜单/;如果将窗口高度减小到略小于菜单大小,它就会出现在上方。
Using Primefaces 2.2.1, if a submenu of a menubar is too big for the browser window, it appears above the menubar (outside of the page) and is unusable.
Simple test case:
Code:
<p:menubar>
<p:submenu label="test">
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
<p:menuitem> <h:commandLink value="test 123"/> </p:menuitem>
...
</p:submenu>
<p:menubar>
If you reduce the window size to some small height, you can see the problem.
It happens in showcase too, although the submenu is then simply hidden.
This makes it unusable for some clients (ipad).
Any workaround or solution ?
UPDATE: I can reproduce the problem on this page: http://wijmo.com/widgets/wijmo-open/menu/ ; if you reduce the window height to just somewhat less than the menu size, it appears above.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你能给我们看一张图片吗?如果您不坚持使用 2.2.1,您也可以升级到
3.0.M4 版本
...我已经在版本 3 中测试了您的代码,并且如果我有很多
menuItems< /code>,出现一个
滚动
,以便轻松导航到最后一项。不管怎样,我认为如果你需要为一个子菜单提供如此多的菜单项,那么设计在某种程度上是错误的!
另一种解决方案是在页面的左角/部分使用
分层或滑动菜单
- 对于这些类型的情况,我更喜欢滑动菜单:您可以一千个子菜单项!http://www.primefaces.org/showcase-labs/ui/menu.jsf编辑
:
由于您无法更改 primefaces 版本,也许是时候在其他地方寻找解决方案了:
我在这里编写了代码(html,css,javascript),您可以在东南框中看到结果 - http ://jsfiddle.net/4UFmk/。
源博客: http://www.kriesi.at/archives/create-a-multilevel-dropdown-menu-with-css-and-improve-it-via-jquery
编辑2:
您不必更改来自 Primefaces(顺便说一句,PF 组件已经使用 jquery),因此您可以使用它的内置 jquery 版本(PF 2 为 1.4,PF 3 为 1.6):
因此您可以在 primefaces 组件内拥有一个简单的 html/jquery 解决方案。
EDIT3:
修复 Primefaces menuBar 实现 - 添加 jquery 函数来修复单击菜单项时子菜单(
ul
)的显示方式:Can you show us an image? Also you can upgrade to
3.0.M4 version
if you aren't stuck with 2.2.1...I've tested your code in version 3 and if I have a lot of
menuItems
, ascroll
is appearing for easy navigation to the last item.Anyway, I think the design is somehow wrong if you need so many menuItems for a single subMenu!
Another solution would be to use a
tiered or sliding menu
in the left corner/part of the page - I prefer the sliding menu exactly for these types of situations: you could have a thousand submenuItems!http://www.primefaces.org/showcase-labs/ui/menu.jsf
EDIT:
Since you can't change the primefaces version, maybe it's time to look for the solution elsewhere:
I've written the code(html,css,javascript) here and you can see the result in the south-east box - http://jsfiddle.net/4UFmk/ .
The source blog: http://www.kriesi.at/archives/create-a-multilevel-dropdown-menu-with-css-and-improve-it-via-jquery
EDIT2:
You do not have to change from Primefaces (by the way PF components are using already jquery), so you can use it's built-in jquery version(1.4 for PF 2 and 1.6 for PF 3):
So you can have a simple html/jquery solution inside primefaces components.
EDIT3:
Fixing the Primefaces menuBar implementation - adding a jquery function to fix the way the submenu(
ul
) is showing on clicking a menu item:这是我根据 @spauny 的建议实施的解决方案。
它适用于 id="menuForm" 元素下的菜单(在我的例子中,这是我的表单)。另外,我仅在 clickend 时显示菜单,如果需要,请将 click() 替换为悬停()。
Here is the solution I implemented, based on @spauny 's suggestions.
It works for menus under an element with id="menuForm" (in my case, this is my form). Also, I display my menus when clickend only, replace click() with hover() if needed.