兩個獨立項目(可能是不同的服務器)中的兩個JSF/JSF頁面和相關的託管bean 使用BackingBeanA.java和BackingBeanB.java將它們命名爲PageA.jsp和PageB.jsp(同樣,獨立的項目)單獨項目中JSF頁面之間的數據傳輸
願望是從PageA.jsp重定向到PageB.jsp和傳遞一個對象(篩選數據)
以下被嘗試:
BackingBeanA.java
public String startPageB() {
try {
FilterData filterData = ...
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)
facesContext.getExternalContext().getRequest();
request.setAttribute("FILTERDATA",filterData);
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.setRequest(request);
externalContext.redirect("http://localhost:8080/PageB/");
}
catch (IOException e) {
e.printStackTrace();
System.out.println(e);
}
return "redirectedData";
}
BackingBeanB.java(在一個單獨的項目,可以是單獨的服務器)
public String getBeanAData() {
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)
facesContext.getExternalContext().getRequest();
FilterData newFilterData = (FilterData)
request.getAttribute("FILTERDATA");
... do stuff
return null;
}
結果: getBeanAData叫,但是: 篩選數據是不是在BackingBeanA空,但在BackingBeanB爲空 - 數據不轉入。
有關如何正確執行此數據傳遞的任何想法?
我應包括在原題:
的Java 1.6.0_22-B03 JSF 1.2 JSTL 1.2 的Eclipse 3.6.0(太陽神) 的Tomcat 6.0.28(需要運行也可以在Weblogic上) IE 7.0.5730.13 Firefox:3.6.12
如果可能,嘗試使用純JSF,不需要HTTP(但可能),不需要JavaScript(句點)。
我如何解決這個問題(現在不夠好):
從父網頁 -
...
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
String initialUrl = externalContext.getInitParameter("RedirectUrl");
String requestDataA = "?ValueA=" + activity.getID();
String requestDataB = "&ValueB=" + activity.getName();
redirectUrl = initialUrl + requestDataA + requestDataB;
externalContext.redirect(redirectUrl);
...
從重定向網頁 -
...
String ownerName = (String) FacesContext.getCurrentInstance().
getExternalContext().getRequestParameterMap().get("ValueB");
String itemId = (String) FacesContext.getCurrentInstance().
getExternalContext().getRequestParameterMap().get("ValueA");
...
的結果是,這個偉大工程 - 用於字符串。這是現在好了。
我想爲以後可能的話什麼:
The same thing, but passing an object.
I know I cannot do that on the request line, but I thought there was a way
similar to a standard HTTP setup where a request attribute is set and the
destination page gets it with a doPost method (do I have this wrong?).
The BalusC answer indicates this is not possible.
So is it really not possible to have a JSF page redirect (starup or whatever)
to an external page, and pass it an object without going to shared storage?
感謝, 約翰
隨着 「獨立工程」 你這樣實際上意味着 「獨立的Web應用程序上下文」? – BalusC 2010-11-18 18:24:09