1

当我从 jsf portlet 单击 jsf 页面的提交按钮时,会调用 jsf bean 的 mymethod。

<h:commandButton id="id1" action="#{Mybean.mymethod}" value="Click" />

public String mymethod() {

    FacesContext fc = FacesContext.getCurrentInstance();
    Object obj = fc.getExternalContext().getResponse();

    if (obj instanceof ActionResponse){
    System.out.println("ActionResponse !");
}   else if (obj instanceof RenderResponse) {
    System.out.println("RenderResponse !");
}
}

但是没有一种类型可以满足 Response 对象。它是什么类型的响应?因为我想弄清楚它是否是 ActionResponse,所以我需要设置 setEvent 方法。我想它应该是 ActionResponse 类型吧?我想知道为什么不是。

<-修改->

现在我得到了行动响应。可能是因为我有 jsf 1.2 而不是 1.1,而且我在不同的系统中。

对于 Portlet A,我在 bean 中设置事件如下,

ar.setEvent("showResults", "true"); //ar is ActionResponse

然后在 Portlet B 的 Portlet 类中,我正在执行以下操作,

public class IPC extends GenericFacesPortlet {

protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException
{
if (request.getAttribute("showResults") == "true") {
request.setAttribute("javax.portlet.faces.viewId", "/JsfB_alt.jsp");
}
super.doView(request, response);

}

@ProcessEvent
public void processIPCEvent(EventRequest eRequest, EventResponse eResponse)
    throws PortletException, IOException
  {
     Event event = eRequest.getEvent();
    if(event.getName().equals("showResults")){
System.out.println("Event encountered !");

    eRequest.setAttribute("showResults", "true");
}

}
}

因此,当我通过设置事件单击 Portlet A 中的按钮时,我要做的是从 Portlet B 的默认视图从 /JsfB.jsp 更改为 /JsfB_alt.jsp。

但是没有监听事件,因为我可以看到“遇到的事件”没有被打印出来。

我什至尝试使用 @Override 将 processIPCEvent 更改为 processEvent,但仍然没有被调用。我希望它会在有任何事件时自动调用,对吧?我觉得在 ar.setEvent() 中设置事件有问题你怎么看?

仅供参考,我正在使用 weblogic server 10.3 和 jsf 1.2

请提出可能是什么问题。

4

2 回答 2

0

可能是由于您的应用程序中使用了portlet 桥接实现。

由于编写 JSF 实现是为了与 servlet API 一起工作,因此它们不能在 portlet 中开箱即用。因此,当创建上下文时,portlet 响应可能会适应servlet 响应。上下文仅返回在创建时传递给它的对象。

在我使用过的桥接器(IBM 实现)中,这些包装器还实现了 portlet 接口,但我不知道需要这样做。

如果您想要更明智的答案,您可能需要说明您的平台、库及其版本。

于 2012-12-28T16:10:26.753 回答
0

我在 portlet.xml 中使用定义为 java 事件 (jsr) <event-definition> and <supported-processing-event>,现在我可以收听它了。

于 2013-01-01T14:21:50.780 回答