歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

Spring Portlet中的webflow

和Spring其他框架一樣,對於webflow,Spring也提供了2個系列,一個是servlet級別的webflow,它在org.springframework.webflow.mvc.servlet 包中,一個是portlet級別的webflow,它在org.springframework.webflow.mvc.portlet包中,我們這裡討論portlet級別的FlowHandler。

FlowHandlerAdapter,正如Spring官方注釋所說的,它將特定的flow定義文件關聯到Flow Handler上。它實現了HandlerAdaptor接口,這個接口的作用是讓Spring的DispatcherPortlet對應各種類型的request(比如actionRequest,resourceRequest,renderRequest,event)可以用特定的Handler來進行處理。這個接口定義了如下方法:

  1. publicinterface HandlerAdapter {
  2. boolean supports(Object handler);
  3. void handleAction(ActionRequest request, ActionResponse response, Object handler) throws Exception;
  4. ModelAndView handleRender(RenderRequest request, RenderResponse response, Object handler) throws Exception;
  5. ModelAndView handleResource(ResourceRequest request, ResourceResponse response, Object handler) throws Exception;
  6. void handleEvent(EventRequest request, EventResponse response, Object handler) throws Exception;
  7. }

 

那麼如何處理呢,在FlowHandlerAdapter中給出了對應的實現,我們以render為例,它的代碼如下:

  1. public ModelAndView handleRender(RenderRequest request, RenderResponse response, Object handler) throws Exception {
  2. FlowHandler flowHandler = (FlowHandler) handler;
  3. checkAndPrepare(request, response);
  4. populateConveniencePortletProperties(request);
  5. FlowException e = clearActionRequestFlowException(request, response, flowHandler);
  6. if (e != null) {
  7. return handleException(e, flowHandler, request, response);
  8. }
  9. String flowExecutionKey = flowUrlHandler.getFlowExecutionKey(request);
  10. if (flowExecutionKey != null) {
  11. return resumeFlowRender(request, response, flowHandler, flowExecutionKey);
  12. } else {
  13. MutableAttributeMap input = flowHandler.createExecutionInputMap(request);
  14. if (input == null) {
  15. input = defaultCreateFlowExecutionInputMap(request);
  16. }
  17. return startFlowRender(flowHandler, input, request, response);
  18. }
  19. }

從這裡我們可以看出,它在第2行中從參數獲得FlowHandler對象,在3行做初始化工作,第4行從render request中填出必要的Portlet屬性。

Copyright © Linux教程網 All Rights Reserved