将数据从一个JSF页面传输到FacesPortlet的ProcessAction()方法

时间:2011-09-09 13:56:30

标签: jsf portlet

这是我想要做的。 我希望jsf page1中的数据在jsf page2中可用,这是一个由page1打开的弹出窗口。 两者都有单独的托管bean。 我尝试使用会话,但它导致空指针。 我以某种方式设法使用javascript中的window.opener()获取page2中的数据。 现在我希望这些数据在FacesPortlet的processAction()方法中可用。 尝试使用request.getParameter,request.getAttributes,都是徒劳的。 经过大量的研究,我以某种方式设法在processAction()方法中发送了一些硬编码数据。但是我无法从page1发送值。 以下是我发送硬编码值的方法。

<form name="uploadbaseline" method="post"
enctype="multipart/form-data" action="<portlet:actionURL><portlet:param name =         "page" value = "someval"/></portlet:actionURL>">

接下来是表单中的其他字段。 我在processAction()方法中得到了像这样的值

System.out.println("valuefrompage1"+request.getParameter("page"));

返回“someval”。 现在我尝试使用以下代码使用javascript从page1分配值。

var val =     window.opener.document.getElementById("BaseLine:EngineModel").value;      
var actionval = "<portlet:actionURL><portlet:param name='page' value=" + val.value + "/></portlet:actionURL>";      
document.uploadbaseline.action = actionval.value;
document.uploadbaseline.submit();

这将返回值“+ val.value +”,而不是“val”变量中的实际值。

请指导我正确的方向。 非常期待您的回复。 感谢。

1 个答案:

答案 0 :(得分:0)

最终找到解决方案。 问题在于我的表单的enctype属性。 这使我无法使用常规request.getParameter访问页面字段。 这需要以不同的方式处理。 这是如何。

for (Iterator requestItems = upload.parseRequest(request).iterator(); requestItems.hasNext();) {
    item = (FileItem) requestItems.next(); // Get each item in the request
    if (!item.isFormField()) {
       //handle the file data
    } else {
       System.out.println((String)item.getString());
    }
}