使用菜单和面板进行JSF 2 Prime Faces导航

时间:2011-08-09 08:28:14

标签: jsf-2 primefaces navigation panel

您好我刚刚使用Primefaces学习JSF 2 我对他们的Panel示例有疑问。我想使用左侧面板作为导航菜单的占位符和内容/页面的中心面板。每次单击菜单时整个页面都会刷新,我想要完成的是当我单击菜单时,只有中心面板会加载相应的页面。这可能是使用jsf 2的素面或其他技术吗?
以下是我正在使用的代码。提前谢谢。

感谢您的快速回复。我尝试了你的建议,但遇到了一些错误。对不起我是jsf2和primefaces的新手。提前谢谢。

错误消息: /homepage.xhtml @ 26,84标记库支持命名空间:http://primefaces.prime.com.tr/ui,但没有为name定义标记:menuItem

以下是我的观点代码(homepage.xhtml)

<p:layout fullPage="true">
<p:layoutUnit position="top" height="75" header="Top" resizable="true" closable="true" collapsible="true">  
        <h:outputText value="North unit content." />  
</p:layoutUnit>  
<p:layoutUnit position="bottom" height="75" header="Bottom" resizable="true" closable="true" collapsible="true">  
        <h:outputText value="South unit content." />  
</p:layoutUnit>        
<p:layoutUnit position="left" width="250" header="Left" resizable="true" closable="true" collapsible="true">  
        <h:outputText value="West unit content." />        
<p:menu type="plain">
<p:submenu label="Mail">

<p:menuItem actionListener="#{navBean.setPage('pageName')}" update="centerPanel" />

<p:menuitem value="Gmail" url="http://www.google.com" />
<p:menuitem value="Hotmail" url="http://www.hotmail.com" />
<p:menuitem value="Yahoo Mail" url="http://mail.yahoo.com" />
</p:submenu>
<p:submenu label="Videos">
<p:menuitem value="Youtube" url="http://www.youtube.com" />
<p:menuitem value="Break" url="http://www.break.com" />
<p:menuitem value="Metacafe" url="http://www.metacafe.com" />
</p:submenu>
<p:submenu label="Social Networks">
<p:menuitem value="Facebook" url="http://www.facebook.com" />
<p:menuitem value="MySpace" url="http://www.myspace.com" />
</p:submenu>
</p:menu></p:layoutUnit>
    <p:layoutUnit position="center" id="centerPanel"> 

    <h:include src="#{navBean.page}.xhtml" />

        This is the center panel
    </p:layoutUnit>        
</p:layout>

这是我的bean NavBean.java的代码

package somePackage;

import javax.faces.bean.*;

@ManagedBean
@SessionScoped
public class NavBean {
      private String page = "login";
}

1 个答案:

答案 0 :(得分:2)

像这样JSF dynamic include using Ajax request

在你的p:menuItem中使用action属性而不是url来制作ajaxcal,在中心面板中你可以使用h:include并在你的支持bean的方法中更改h:include中src属性的值。它也可以是actionListener而不是action。

托管bean -

@ManagedBean
@SessionScoped
public class NavBean {

    private String page = "default";

    //getter/setter for page

查看 -

<p:menuItem actionListener="#{navBean.setPage('pageName')}" update="centerPanel" />

//center panel with id="centerPanel"
<h:include src="#{navBean.page}.xhtml" />

你不是要刷新页面而是制作ajaxcal,更改值页面并更新中心面板。

相关问题