简体   繁体   English

使用MenuModel支持的菜单进行Primefaces布局导航

[英]Primefaces layout navigation using MenuModel backed menu

Using PrimeFaces, I want to update/refresh a pages central layout unit based on user interaction with a menu (programmatically created MenuModel) that's included in the same pages east layout unit. 使用PrimeFaces,我想基于用户与包含在同一页面东部布局单元中的菜单(以编程方式创建的MenuModel)的用户交互来更新/刷新页面中央布局单元。 From what I can tell, this is not possible, but very well could be wrong. 据我所知,这是不可能的,但很可能是错误的。 Thanks! 谢谢!

subMenu = new Submenu();
subMenu.setLabel("Sales");  
subMenu.setIcon("ui-icon ui-icon-home");

- --

private String currentPage; //holds identifier of current content panel

- --

<!-- navigation panel -->
<p:layoutUnit position="west" resizable="false" size="216">
    <ui:include src="./includes/navigationMenu.xhtml" />
</p:layoutUnit>  

<!-- content panel -->
<p:layoutUnit position="center">
    <ui:include src="/views/#{navigationBean.currentPage}.xhtml" />         
</p:layoutUnit>

Thanks! 谢谢!

It's just a question: Why do you create a menu programmatically? 只是一个问题:为什么要以编程方式创建菜单?

Other than that almost everything it's possible: try to include the ui:include into a form component with an id (let's say myFormId ) and try to update this form every time a submenu item is selected; 除了几乎所有的一切之外,还可能:尝试将ui:include在具有ID的表单组件中(比如myFormId ),并在每次选择子菜单项时尝试更新此表单; Ok so let's do that programmatically: 好的,让我们以编程方式进行操作:

MenuItem item = new MenuItem();
item.setValue("Dynamic Menuitem");
item.setUrl("#");                    //add whatever attribute you want to menuItem
item.setUpdate("myFormId");
subMenu.getChildren().add(item);     //then add the menuItem object to subMenu as a child.

You can find here the menuItem API 您可以在这里找到menuItem API

I implemented a listener.. 我实现了一个监听器。

MenuItem thisItem = (MenuItem)event.getComponent();
String navigateTo = thisItem.getId();
BeanManager beanManager = new BeanManager();
NavigationBean navBean = (NavigationBean)beanManager.get("navigationBean");
navBean.setCurrentPage(navigateTo);

added it to the MenuItem as well as a call to the the templates refresh()... 将其添加到MenuItem以及对模板refresh()的调用...

item.addActionListener(new MenuItemListener());
item.setOnsuccess("refresh()");

added the refresh method... 添加了刷新方法...

function refresh(){
    document.location="#{request.contextPath}/faces/views/main.xhtml";
}

I really don't care for this solution, but it's better than the alternative, having untestable menu creation logic in markup. 我确实不在乎此解决方案,但是它比替代方法更好,因为在标记中具有不可测试的菜单创建逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM