【发布时间】:2017-01-03 14:30:27
【问题描述】:
我有一个问题。 如何使用按钮将新的 xhtml 文件加载到 p:panel 并仍然更改 url。我想使用命令按钮将新的 xhtml 文件加载到 p:panel 但我仍然希望更改网站 url。
我为什么要这样做。
我想这样做是因为我希望我的网站有多个页面,每个页面都有我的工具栏。我不想在每个页面中复制工具栏的代码。 - 剂量有意义吗?如果有人知道如何提供帮助,请告诉我。
我的代码。 index.xhtml
滚动完成,直到找到类值为“ClassPanel”的 p:panel 单击工具栏中的按钮时,我希望 p:panel 加载新的 xhtml 文件。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>LEEXV</title>
</h:head>
<h:body>
<style>
</style>
<h:form >
<p:growl id="messages"/>
<p:toolbar id="stickymenu" style=" max-height:60px; margin-top: auto; ">
<f:facet name="left">
<f:facet name="left">
</f:facet>
<f:facet name="right">
<p:growl id="growl" life="2000"/>
<p:inputText style="margin-right:40px;" placeholder="Search Crawly"/>
<p:spacer width="10px;"/>
<p:commandButton value="Ajax Action" action="#{navigationView.gotoSecond}" style=" width: 90px; height: 40px;"/>
<p:spacer width="20px;" />
<p:commandButton id="Support" type="ComButton" style=" width: 90px; height: 40px;" value="Donate"/>
<p:tooltip id="toolTipGrow" for="Support" value="Find out how you can help us help you!"
showEffect="clip" hideEffect="explode" />
<p:spacer width="20px;"/>
<p:commandButton type="ComButton" style=" width: 90px; height: 40px;" value="Update"/>
<p:spacer width="20px;"/>
<p:commandButton type="ComButton" style="width: 90px; height: 40px; margin-top: 6px;" value="Shop"/>
</f:facet>
</f:facet>
<f:facet name="right">
</f:facet>
</p:toolbar>
<p:sticky target="stickymenu"/>
</h:form>
<p:panel class="ClassPanel" >
<ui:composition id="LoadNewpages">
<ui:param id ="" name="defaultHeader" value="#{HomeHtml.gotoSecond}" />
</ui:composition>
</p:panel>
</h:body>
</html>
我的代码。 newjsf.xhtml
这是我想在面板中加载的代码。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<body>
<h:outputText value="hello"/>
</body>
</html>
我的代码。 NavigationView.java
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
@ManagedBean
public class NavigationView implements Serializable {
public String gotoSecond() {
return "newjsf";
}
}
如果您不明白,请尝试帮助我完成这部分。我有提出不好问题的历史
如何使用按钮加载 xhtml 文件。 基本上,我如何将 xhtml 文件动态加载到 p:panel。
【问题讨论】:
-
只需创建一个模板。
-
@BalusC。我不知道该怎么做。而且这个问题也不是重复的。请通读整个对话,而不仅仅是标题。标题本身是重复的,但对话不是。
-
副本显示了如何。请注意,重复不是关于问题,而是关于答案。在这里复制粘贴答案是没有意义的。
标签: jsf jsf-2 primefaces