两个独立项目(可能是不同的服务器)中的两个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