我有主页,仪表板页面和addfield页面。主页有仪表板的链接,仪表板有添加字段的链接。单击命令链接时,这工作正常。 我想在主页的仪表板和仪表板页面中显示addfield页面。当我使用include来显示页面时,它包含页面并显示。
当我想在点击主页命令链接时显示dashBoard页面时,它不能与
一起使用<f:ajax event="action" render="panelid">
和
<h:panelgroup id="panelid" rendered="#{home.showPage}">
<h:include src="/dashboard.xhtml">
</h:panelGroup>
我在调试时检查了它没有调用bean方法。
HomePage.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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition>
<h:form>
<h:panelGrid columns="4" width="100%">
<h:commandLink action="#{home.showPage}" value="Home">
<f:param name="pageName" value="home" />
<f:ajax event="action" render="pgdb"/>
</h:commandLink>
<h:commandLink action="#{home.showPage}"
value="DashBoard">
<f:param name="pageName" value="dashBoard" />
<f:ajax event="action" render="pgdb"/>
</h:commandLink>
</h:panelGrid>
<h:panelGroup id="pgdb" rendered="#{home.showDashBoard}">
<ui:include src="/DashBoard.xhtml"/>
</h:panelGroup>
</h:form>
</ui:composition>
</html>
DashBoard.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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:form>
<h:panelGrid columns="2">
<table border="1" width="30%">
<tr>
<h:commandLink action="#{dashBoard.showPage}"
value="Add Field">
<f:param name="pageName" value="addField" />
</h:commandLink>
</tr>
</table>
</h:panelGrid>
<ui:include src="AddField.xhtml"/>
</h:form>
</html>
AddField.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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition>
<h:form>
<h:outputText value=FirstName" />
<h:outputText value="LastName" />
</h:panelGrid>
</h:form>
</ui:composition>
</html>
home.java
package ims.com.home;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@ManagedBean(name="home")
@Scope
@Component
public class Home implements Serializable {
@ManagedProperty(value = "#{param.pageName}")
private String pageName;
private boolean showDashBoard = false;
public boolean isShowDashBoard() {
return showDashBoard;
}
public void setShowDashBoard(boolean showDashBoard) {
this.showDashBoard = showDashBoard;
}
public String showPage() {
if (pageName == "home") {
showDashBoard = false;
return "HomePage";
}
if (pageName.equals("dashBoard")) {
showDashBoard = true;
return "HomePage";
}
}
public String getPageName() {
return pageName;
}
public void setPageName(String pageName) {
this.pageName = pageName;
}
}
dashBoard.java
package ims.com.dashboard;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.view.ViewScoped;
@ManagedBean(name="dashBoard")
@ViewScoped
public class DashBoard implements Serializable {
@ManagedProperty(value = "#{param.pageName}")
private String pageName;
public String showPage() {
if (pageName == "addField") {
return "AddField";
}
}
public void setPageName(String pageName) {
this.pageName = pageName;
}
}