我想创建一个带有请求参数和 requestScoped bean 的主从屏幕,但视图参数没有被填充。
调用重定向的链接:
<h:form>
<p:dataTable var="visit" value="#{visitBean.findAllVisits()}">
<p:column headerText="mdh">
<p:commandLink action="#{visitDetailBean.seeVisitDetails(visit)}">
<h:graphicImage library="images" name="details.png"/>
</p:commandLink>
</p:column>
....
其背后的方法:
public String seeVisitDetails(Visit visit) throws IOException {
return "/pages/mdh-details.xhtml?visitId=" + visit.getId()+ ";faces-redirect=true";
}
详情 xhtml 页面:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core">
<f:metadata>
<f:viewParam name="visitId" value="#{visitDetailBean.currentVisitId}" />
</f:metadata>
<ui:composition template="/templates/masterLayout.xhtml">
<ui:define name="content">
<h:outputText value="#{visitDetailBean.currentVisit.name}"/>
test
</ui:define>
</ui:composition>
最后是详细信息 Bean:
private long currentVisitId;
public void setCurrentVisitId(long currentVisitId) {
this.currentVisitId = currentVisitId;
}
public long getCurrentVisitId() {
return currentVisitId;
}
public Visit getCurrentVisit() {
return visitService.findVisit(currentVisitId);
}
currentVisitId 始终为 0.. 我实际上找不到它。