gpt4 book ai didi

jsf-2 - 更改

dynamically on click of link from menu through Ajax的内容

转载 作者:行者123 更新时间:2023-12-04 18:22:40 25 4
gpt4 key购买 nike

我在 Tomcat 7 上使用带有 Primefaces 的 JSF2。我在 baseLayout.xhtml 中创建了一个布局,如下所示:-

<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="50" id="top">
<h:form>
<ui:include src="/template/header.xhtml" />
</h:form>
</p:layoutUnit>
<p:layoutUnit position="south" size="20">
<h:form>
<ui:include src="/template/footer.xhtml" />
</h:form>
</p:layoutUnit>
<p:layoutUnit position="west" size="400">
<h:form>
<ui:include src="/template/menu.xhtml" />
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center" size="400">
<h:panelGroup id="centerContentPanel">
<ui:include src="#{navigationBean.pageName}.xhtml" />
</h:panelGroup>
</p:layoutUnit>
</p:layout>
</h:body>

我想动态更改 的来源中心内容面板 不刷新整个页面,只刷新 中心内容面板 即点击 menu.xhtml 中的链接,如下所示: -
<h:form id="form2">
<f:ajax render=":centerContentPanel" execute="@this">
<h:commandLink value="page1" action="#{navigationBean.doNav}" >
<f:param name="test" value="/pages/page1" />
</h:commandLink>
<h:commandLink value="page2" action="#{navigationBean.doNav}" >
<f:param name="test" value="/pages/page2" />
</h:commandLink>
</f:ajax>
</h:form>

.我尝试这样做,但它刷新了整个页面而不更改 URL,当我再次刷新它时,新页面被包含在内。我不知道发生了什么。我的 NavigationBean 如下:-
public class NavigationBean {

private String pageName="/template/body";

public NavigationBean() {
}

public String doNav() {
System.out.println("Hello");
String str = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("test");
this.pageName = str;
return pageName;
}

public String getPageName() {
return pageName;
}

public void setPageName(String pageName) {
this.pageName = pageName;
}
}

最佳答案

更改 doNav()进入 void ,无需返回值...(因为它会导致您的 commandLink 重新加载页面...)您已经更新了 pageName<ui:include src="#{navigationBean.pageName}.xhtml" />
中使用
doNav应该是这样的:

public void doNav() {
System.out.println("Hello");
String str = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("test");
this.pageName = str;

}

您的 action="..." 的返回值导致 refreshes the whole page without changing the URL

关于jsf-2 - 更改<p :layoutUnit> dynamically on click of link from menu through Ajax的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10336995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com