如何在PrimeFaces中更新LayoutUnit使其呈现? [英] How to update a LayoutUnit in PrimeFaces to get it rendered?
问题描述
我在xhtml中有一个fullPage布局,其中菜单位于菜单的最西端,而布局的内容位于中心.
I have a fullPage layout in my xhtml with a west-positioned layoutUnit for the menu and a center-positioned one for the content.
我已经实现了几个居中的layotUnit,我想根据所选的menuItem渲染它们.
I have implemented several center-positioned layotUnits, and I want to render them according to the menuItem selected.
运行该应用程序时,它不会刷新layoutUnit,直到我在浏览器中单击刷新(IE8-公司标准).
When I run the application, it won't refresh the layoutUnit, until I click refresh in the browser (IE8 - company standard).
xhtml如下:
<h:body>
<h:form>
<p:layout fullPage="true" id="allLayout">
<p:layoutUnit position="west" header="Menu" collapsible="true">
<p:menu>
<p:submenu label="Resources">
<p:menuitem value="Option1" action="#{menu.setSelectedMenu(menu.OPT1)}" update="allLayout"/>
<p:menuitem value="Option2" action="#{menu.setSelectedMenu(menu.OPT2)}" update="allLayout"/>
</p:submenu>
</p:menu>
</p:layoutUnit>
<p:layoutUnit position="center" rendered="#{menu.selectedMenu == menu.OPT1}">
<p:outputLabel value="This is the content option 1 (default)."/>
</p:layoutUnit>
<p:layoutUnit position="center" rendered="#{menu.selectedMenu == menu.OPT2}">
<p:outputLabel value="This is the content option 2."/>
</p:layoutUnit>
</p:layout>
</h:form>
</h:body>
其对应的bean是:
@ManagedBean
@SessionScoped
public class Menu {
private final int OPT1 = 1;
private final int OPT2 = 2;
private int selectedOption;
public Menu() {
selectedMenu = OPT1;
}
public int getSelectedOption() {
return selectedOption;
}
public void setSelectedOption(int selectedOption) {
this.selectedOption = selectedOption;
}
public int getOPT1() {
return OPT1;
}
public int getOPT2() {
return OPT2;
}
}
推荐答案
我认为您不想创建多个中心布局单元.我认为使用单个布局单元并更改该单个单元中的内容会更好.根据您的工作,您可能需要对该单元使用一些模板.我想说,也许最好的方法是将不同的内容放在面板上,然后将它们包装在要更新的父面板中,以显示所需的内容.
I don't think that you want to create multiple center layout units. I think you will be better off with a single layout unit and change the content within that single unit. Depending on what you are doing you may want to use some templating for that unit. I would say that probably your best approach is to put your different content on panels then wrap them in a parent panel that you will update in order to show the content you want.
<p:layout fullPage="true" id="allLayout">
<p:layoutUnit position="west" header="Menu" collapsible="true">
<p:menu>
<p:submenu label="Resources">
<p:menuitem value="Option1"
action="#{menu.setSelectedMenu(menu.OPT1)}" update="optionPanel" />
<p:menuitem value="Option2"
action="#{menu.setSelectedMenu(menu.OPT2)}" update="optionPanel" />
</p:submenu>
</p:menu>
</p:layoutUnit>
<p:layoutUnit position="center">
<p:panel id="optionPanel">
<p:panel id="opt1Panel" rendered="#{menu.selectedMenu == menu.OPT1}">
<p:outputLabel value="This is the content option 1 (default)." />
</p:panel>
<p:panel id="opt2Panel"
rendered="#{menu.selectedMenu == menu.OPT2}">
<p:outputLabel value="This is the content option 2 (default)." />
</p:panel>
</p:panel>
</p:layoutUnit>
</p:layout>
这篇关于如何在PrimeFaces中更新LayoutUnit使其呈现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!