我創建了一個Spring MVC portlets項目,並試圖在兩個我的portlet(SenderPortlet和ConsumerPortlet)之間實現IPC。 一切工作正常,但我需要初始化我放在會話中的bean模型,所以我已經在初始化bean的方法上使用了SessionAttributes註釋和ModelAttribute註釋。我有兩種狀態:在Spring MVC portlets中的IPC
- 投入的ModelAttribute註釋之前: 一切工作正常。我的意思是IPC。
- 投入的ModelAttribute註釋後:
org.springframework.web.bind.annotation.support.HandlerMethodInvocationException: Failed to invoke handler method [public void com.test.SenderController.myAction(org.springframework.web.bind.support.SessionStatus,javax.portlet.ActionResponse)]; nested exception is java.lang.IllegalStateException: Current request is not of type [javax.portlet.RenderRequest]: [email protected]
注意myAction是在其行動所映射的方法:當我點擊那個火IPC發送事件的動作拋出異常。此方法設置IPC事件。下面是它的簽名:
@ActionMapping("action") public void myAction(SessionStatus status, ActionResponse response) { // some code... }
我不明白爲什麼,因爲我加入的ModelAttribute註解這個異常被觸發。
你能幫我解決嗎?
非常感謝。
問候,
EDIT 1個更多代碼
ConsumerPortlet.java
@Controller(value = "ConsumerPortlet")
@SessionAttributes(value="products")
@RequestMapping("VIEW")
public class ConsumerPortlet {
@RequestMapping
public String handleRenderRequest(RenderRequest request, RenderResponse response, Model model) {
try {
//some code
return "page";
}
@ModelAttribute("products")
public List<ProductBean> initilizeProduct(RenderRequest renderRequest){
//some code
return productList;
}
@EventMapping(value ="{http://liferay.com/events}myEvent")
public void processEvent(EventRequest request, EventResponse response) throws PortletException, IOException {
javax.portlet.Event event = request.getEvent();
String testValue = (String) event.getValue();
System.out.println("IPC test value: "+testValue);
}
SenderPortlet.java
@Controller(value = "SenderPortlet")
@SessionAttributes(value="products")
@RequestMapping("VIEW")
public class SenderPortlet {
@RequestMapping
public String handleRenderRequest(RenderRequest request,
RenderResponse response, Model model) {
return "page2";
}
@ModelAttribute("products")
public List<ProductBean> initilizeProduct(RenderRequest renderRequest){
PortletSession ps = renderRequest.getPortletSession();
List<ProductBean> productList = (List<ProductBean>) ps.getAttribute("products",PortletSession.APPLICATION_SCOPE);
return productList;
}
@ActionMapping("myAction")
public void myAction(SessionStatus status,
ActionResponse response)
{
QName qname = new QName("http://liferay.com/events", "myEvent", "x");
response.setEvent(qname, "test-value sent");
status.setComplete();
}
的portlet.xml
<portlet>
<portlet-name>sender</portlet-name>
<portlet-class>
org.springframework.web.portlet.DispatcherPortlet
</portlet-class>
<init-param>
<name>contextConfigLocation</name>
<value>/WEB-INF/sender-portlet.xml</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>Sender</title>
</portlet-info>
<supported-publishing-event>
<qname xmlns:x="http://liferay.com/events">x:myEvent</qname>
</supported-publishing-event>
</portlet>
<portlet>
<portlet-name>consumer</portlet-name>
<portlet-class>
org.springframework.web.portlet.DispatcherPortlet
</portlet-class>
<init-param>
<name>contextConfigLocation</name>
<value>/WEB-INF/consumer-portlet.xml</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>Consumer</title>
</portlet-info>
<supported-processing-event>
<qname xmlns:x="http://liferay.com/events">x:myEvent</qname>
</supported-processing-event>
</portlet>
<event-definition>
<qname xmlns:x="http://liferay.com/events">x:myEvent</qname>
<value-type>java.lang.String</value-type>
</event-definition>
的Liferay-portlet.xml中
<portlet>
<portlet-name>sender</portlet-name>
<icon>/icon.png</icon>
<instanceable>true</instanceable>
<header-portlet-css>/css/test.css</header-portlet-css>
<footer-portlet-javascript>/js/test.js</footer-portlet-javascript>
</portlet>
<portlet>
<portlet-name>consumer</portlet-name>
<icon>/icon.png</icon>
<instanceable>true</instanceable>
<header-portlet-css>/css/test.css</header-portlet-css>
<footer-portlet-javascript>/js/test.js</footer-portlet-javascript>
</portlet>
Liferay的6.2.10.12 春3.0.7.RELEASE
它看起來並不像這樣以任何方式IPC相關 - 而您的portlet的操作處理程序的佈線問題?請發佈更多代碼 - 例如更多的揭示這個問題的portlet類。 –
@OlafKock我更新了帖子..謝謝 – javaxiss